如何将HTTP POST与"application/octet-stream"一起使用在Android中? (Microsoft认知视频) [英] How to use HTTP POST with "application/octet-stream" in Android? (Microsoft Cognitive Video)

查看:1213
本文介绍了如何将HTTP POST与"application/octet-stream"一起使用在Android中? (Microsoft认知视频)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android中使用视频认知服务. Microsoft提供的示例在C#中使用. 视频功能正在将URL发送到服务器, 因此,我认为可以使用HTTP POST在Android中发送URL.

I want to use the Video Cognitive Service in Android. The sample that Microsoft provided is used in C#. The video function is sending an URL to the server, So I think it is possible using HTTP POST to send an URL in Android.

http://ppt.cc/V1piA

我遇到的问题是我不知道"application/octet-stream"中的URL格式,并且在Microsoft网站上也没有看到该示例.

The problem I met is that I don't know the URL format in "application/octet-stream", and I didn't see the example on the Microsoft website.

是否可以在Android中使用HTTP POST将下载的视频上传到服务器,并且我可以从服务器获取分析结果?

Is it possible using HTTP POST in Android to upload a downloaded video to the server, and I can get the analysis result from the server?

如果可能,将请求发送到服务器的HTTP POST的格式是什么?

If possible, what is the format of the HTTP POST to send request to the server?

谢谢.

推荐答案

您可以尝试使用类似方法发送图像文件以进行认知服务的面部检测. 使用org.apache.httpcomponents :: httpclient:

You may try something like this to send image files for cognitive-services face detect. Using 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());
        }
    }

这篇关于如何将HTTP POST与"application/octet-stream"一起使用在Android中? (Microsoft认知视频)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆