如何将HTTP POST与“一起使用”;应用程序/八位字节流“;在Android中?(微软认知视频)
我想在Android中使用视频认知服务。 Microsoft提供的示例用于C#。 视频功能正在向服务器发送URL, 所以我认为在Android中使用HTTPPOST发送URL是可能的 我遇到的问题是,我不知道“应用程序/八位字节流”中的URL格式,而且我在Microsoft网站上也没有看到该示例 是否可以在Android中使用HTTP POST将下载的视频上传到服务器,然后我可以从服务器获得分析结果 如果可能,向服务器发送请求的HTTP POST的格式是什么 谢谢 HTTPPOST指的是,指的是媒体类型—在本例中,指的是特定于应用程序的八位字节或字节流 不幸的是,这是非常主观的,因为通过HTTP操作上传内容的机制可能是首选的方式。可以这样说,您将创建内容的输入流,使用您选择的机制格式化POST请求:如何将HTTP POST与“一起使用”;应用程序/八位字节流“;在Android中?(微软认知视频),android,microsoft-cognitive,Android,Microsoft Cognitive,我想在Android中使用视频认知服务。 Microsoft提供的示例用于C#。 视频功能正在向服务器发送URL, 所以我认为在Android中使用HTTPPOST发送URL是可能的 我遇到的问题是,我不知道“应用程序/八位字节流”中的URL格式,而且我在Microsoft网站上也没有看到该示例 是否可以在Android中使用HTTP POST将下载的视频上传到服务器,然后我可以从服务器获得分析结果 如果可能,向服务器发送请求的HTTP POST的格式是什么 谢谢 HTTPPOST指的是,指的
执行post后,请查阅API文档以了解预期的返回类型。您可以尝试类似的方法来发送图像文件以用于认知服务面部检测。 使用org.apache.httpcomponents::httpclient:
@Test
public void testSendBinary() throws MalformedURLException {
File picfile = new File("app/sampledata/my_file.jpeg");
if (!picfile.exists()) throw new AssertionError();
HttpClient httpclient = HttpClients.createDefault();
try {
URIBuilder builder = new URIBuilder("https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect");
builder.setParameter("returnFaceId", "true");
builder.setParameter("returnFaceLandmarks", "false");
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "application/octet-stream");
request.setHeader("Ocp-Apim-Subscription-Key", "***");
// Request body
request.setEntity(new FileEntity(picfile));
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());
}
}
您可以尝试类似的方法发送图像文件,用于认知服务面部检测。 使用org.apache.httpcomponents::httpclient:
@Test
public void testSendBinary() throws MalformedURLException {
File picfile = new File("app/sampledata/my_file.jpeg");
if (!picfile.exists()) throw new AssertionError();
HttpClient httpclient = HttpClients.createDefault();
try {
URIBuilder builder = new URIBuilder("https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect");
builder.setParameter("returnFaceId", "true");
builder.setParameter("returnFaceLandmarks", "false");
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "application/octet-stream");
request.setHeader("Ocp-Apim-Subscription-Key", "***");
// Request body
request.setEntity(new FileEntity(picfile));
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());
}
}
谢谢你的回答。我知道如何向服务器发送URL,但我不知道当我想在Android中通过HTTP POST上传下载的视频时Microsoft server想要的格式。我猜,基于他们请求应用程序/八位字节流的事实,他们将应用启发式来确定流的实际内容。这种媒体类型对于任何将以8位纯方式传输的内容来说都是包罗万象的?在URL上,只需将正文作为应用程序/八位字节流发送(即按原样发送流),即可接收输入格式。关键信息:MP4、MOV或WMV,上限为100Mb感谢您的回答。我知道如何向服务器发送URL,但我不知道当我想在Android中通过HTTP POST上传下载的视频时,Microsoft server需要什么格式。我猜测,基于他们请求应用程序/八位字节流的事实,他们将应用启发式来确定流的实际内容。这种媒体类型对于任何将以8位纯方式传输的内容来说都是包罗万象的?在URL上,只需将正文作为应用程序/八位字节流发送(即按原样发送流),即可接收输入格式。关键信息:MP4、MOV或WMV,上限为100MB