在Android

时间:2017-06-02 14:06:06

标签: java android apache microsoft-cognitive emotion

我正在android中构建一个应用程序,它将记录视频,将其存储在本地存储中并将其发送给Emotion API进行分析。但是,我无法组建请求正文。我使用以下示例: https://westus.dev.cognitive.microsoft.com/docs/services/5639d931ca73072154c1ce89/operations/56f8d40e1984551ec0a0984e/console

我只需要知道如何形成请求和视频文件。

1 个答案:

答案 0 :(得分:0)

除了Maria的评论之外,我还尝试了以下问题中的前两个解决方案:

How do I send a file in Android from a mobile device to server using http?

我建议通过前2个解决方案,因为他们最有可能工作。在RESPONSE,收到Operation-LocationOID,可以HTTP GET拨打电话:

https://westus.api.cognitive.microsoft.com/emotion/v1.0/operations/{oid}

文档:https://westus.dev.cognitive.microsoft.com/docs/services/5639d931ca73072154c1ce89/operations/56f8d4471984551ec0a0984f

我用于GET请求的代码:

    URIBuilder statusBuilder = new URIBuilder("https://westus.api.cognitive.microsoft.com/emotion/v1.0/operations/{oid});
statusBuilder.setParameter("oid", {oid});

URI uriStatus = statusBuilder.build();
HttpGet statusRequest = new HttpGet(uriStatus);
statusRequest.setHeader("Ocp-Apim-Subscription-Key", {key});

HttpResponse statusResponse = httpclient.execute( statusRequest );
HttpEntity entity = statusResponse.getEntity();
Header[] statusHeaders = statusResponse.getAllHeaders();
    for (Header header : statusHeaders) {
        System.out.println( "Key : " + header.getName()
            + " ,Value : " + header.getValue() );
    }