gpt4 book ai didi

java - Java 创建人员组的 Microsoft 认知服务 Face API 错误

转载 作者:行者123 更新时间:2023-11-30 07:09:53 25 4
gpt4 key购买 nike

此代码用于使用 Java 创建人员组。

import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample
{
public static void main(String[] args)
{
HttpClient httpclient = HttpClients.createDefault();

try
{
URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/face/v1.0/persongroups/personGroupId");


URI uri = builder.build();
HttpPut request = new HttpPut(uri);
request.setHeader("Content-Type", "application/json");
request.setHeader("Ocp-Apim-Subscription-Key", "mysubscriptionkey");


// Request body
StringEntity reqEntity = new StringEntity("{body}");
request.setEntity(reqEntity);

HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();

if (entity != null)
{
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}

当我运行此代码时,出现以下错误:

{"error":{"code":"BadArgument","message":"Request body is invalid."}}

我能做些什么来修复它。我在互联网上没有找到使用java创建人员组的示例,所以我无法修复它。

最佳答案

正如错误所示,HTTP 请求正文的格式错误为 {body}

请查看 API页面上标记为请求正文的部分下。您需要提供名称,并且可以选择添加用户数据。

StringEntity reqEntity = new StringEntity("{" +
"\"name\":\"group1\"," +
"\"userData\":\"user-provided data attached to the person group\""+
"}")

您可以在 GitHub SDK 上找到一些其他 Java 示例页。

关于java - Java 创建人员组的 Microsoft 认知服务 Face API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39403269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com