[英]C# error in an HTTP request header
I want to use the service Microsoft Cognitive Service.我想使用 Microsoft Cognitive Service 服务。 I wrote this code :我写了这段代码:
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);
}
After execution I see :执行后我看到:
I don't understand where is my error for a header.我不明白我的标题错误在哪里。 Thank's for your help.谢谢你的帮助。
thank you for answer.谢谢你的答案。 I understand the problem.我明白这个问题。 i replace this :我替换这个:
byte[] byteData = Encoding.UTF8.GetBytes("{\\"url\\":\\" http://im...8.jpg \\"}"); byte[] byteData = Encoding.UTF8.GetBytes("{\\"url\\":\\" http://im...8.jpg \\"}");
Now my problem is to obtain the result on this form :现在我的问题是在这个表格上获得结果:
[
{ {
"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 a lot for help!非常感谢您的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.