你好,我试图触发对以下API的POST调用。这是代码:
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key);
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["returnFaceId"] = "true";
queryString["returnFaceLandmarks"] = "false";
queryString["returnFaceAttributes"] = "age,gender";
var filebytes = File.ReadAllBytes(@"C:\Users\user1\Desktop\IMG.jpg");
var uri = "https://southeastasia.api.cognitive.microsoft.com/face/v1.0/detect?" + queryString;
HttpResponseMessage response;
using (var content = new ByteArrayContent(filebytes))
{
response = client.PostAsync(uri, content).Result;
var result = response.Content.ReadAsStringAsync().Result;
}
我在
result
中遇到了以下错误:{"error":{"code":"BadArgument","message":"JSON parsing error."}}
如果我使用application/json
并传递一个http链接,这段代码可以正常工作。
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
。 - Vitox