2016-05-06 8 views
-1

サービスMicrosoft Cognitive Serviceを使用したいと思います。 私はこのコードを書いた:私は参照を実行した後HTTP要求ヘッダーのC#エラー

static async void MakeRequest() 
    { 
     var client = new HttpClient(); 
     var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); 

     //Request headers 
     client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "......."); 

     //Requests parameters 
     queryString["returnFaceId"] = "true"; 
     queryString["returnFaceLandmarks"] = "false"; 
     queryString["returnFaceAttributes"] = "age,smile,gender"; 
     var uri = "https://api.projectoxford.ai/face/v1.0/detect?" + queryString; 
     //var uri = "https://api.projectoxford.ai/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,smile,gender"; 
     HttpResponseMessage response; 

     //request body 
     byte[] byteData = Encoding.UTF8.GetBytes("http://ima..uniserv...248.jpg"); 

     using (var content = new ByteArrayContent(byteData)) 
     { 
      content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); 
      // 
      response = await client.PostAsync(uri, content); 
     } 
     Console.WriteLine(response); 

    } 

HTTP 400 error

ヘッダーのための私の誤差がある場合、私は理解していません。 ありがとうございました。

+1

画像を投稿に直接添付してください。さらに、これはサーバーエラーで、最初にデバッグする必要があります –

+0

なぜJPEG画像を投稿して、それがJSONであると主張していますか? – SLaks

答えて

0

回答ありがとうございます。 私はこの問題を理解しています。 私はこれを次のように置き換えます:

バイト[] byteData = Encoding.UTF8.GetBytes( "{\" url \ ":\" http://im...8.jpg \ "}");

今私の問題は、このフォームで結果を得ることである:

[ 

{

"faceId": "bed2c25c-3fab-4a72-b32b-a44797b1bf1a", 

"faceRectangle": { 

    "top": 98, 

    "left": 135, 

    "width": 201, 

    "height": 201 

}, 

"faceAttributes": { 

    "smile": 0.002, 

    "gender": "male", 

    "age": 30.6 

} 

}

]

助けのためにたくさんthaks!

関連する問題