Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为Microsoft认知服务API编写二进制输入的POST方法_C#_Post_Unity3d - Fatal编程技术网

C# 如何为Microsoft认知服务API编写二进制输入的POST方法

C# 如何为Microsoft认知服务API编写二进制输入的POST方法,c#,post,unity3d,C#,Post,Unity3d,Microsoft认知服务API在帖子正文中支持两种输入方法:原始图像二进制或图像URL。通过使用此API的在线测试控制台,我知道HTTP请求应该是什么样子 `POST https://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Faces HTTP/1.1 Content-Type: application/json Host: api.projectoxford.ai Content-Length: 125 Ocp-Apim

Microsoft认知服务API在帖子正文中支持两种输入方法:原始图像二进制或图像URL。通过使用此API的在线测试控制台,我知道HTTP请求应该是什么样子

`POST https://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Faces HTTP/1.1
Content-Type: application/json
Host: api.projectoxford.ai
Content-Length: 125
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••

{"url":"someImageURL"}`
我正在向UnityWebRequest提出请求,目前为止我所拥有的是

string url = "https://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Faces";
UnityWebRequest www = new UnityWebRequest(url, "POST");
www.SetRequestHeader("Content-Type", "application/json");
www.SetRequestHeader("Ocp-Apim-Subscription-Key", APIKEY);

如何将我的byte[]图像包含在此请求中?

我只是通过Unity的WWW,而不是UnityWebRequest找到了它

我成功地使用了以下代码:

    // Add WWW Headers needed
    WWWForm form = new WWWForm();
    var headers = form.headers;
    headers["Content-Type"] = "application/octet-stream";
    headers["Ocp-Apim-Subscription-Key"] = Key;

    //Start WWW Request
    WWW www = new WWW(url, image, headers);

    StartCoroutine(WaitForRequest(www));

我只是通过Unity的WWW,而不是UnityWebRequest找到了答案

我成功地使用了以下代码:

    // Add WWW Headers needed
    WWWForm form = new WWWForm();
    var headers = form.headers;
    headers["Content-Type"] = "application/octet-stream";
    headers["Ocp-Apim-Subscription-Key"] = Key;

    //Start WWW Request
    WWW www = new WWW(url, image, headers);

    StartCoroutine(WaitForRequest(www));