对于我生命中的爱我只是无法弄清楚为什么我的jason格式都有问题,我使用Microsoft Face API 1.0在组内创建一个人
这是我的代码
protected async void btnAddFaces_Click(object sender, EventArgs e)
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
string personGroupId = txtFriendList.Text.ToLower();
string persons = txtfriendName.Text.ToLower();
// Request headers
client.DefaultRequestHeaders.Add
("Ocp-Apim-Subscription-Key", "{YourKey}");
// Request parameters
var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/
persongroups/wowlist/persons?" + queryString;
// HttpResponseMessage response;
// not sure but I think here is my problem
string body = "{\"name\":\"" + "waheed" + "," + "\"}";
// Request body
using (var content = new StringContent
(body, Encoding.UTF8, "application/json"))
{
await client.PutAsync(uri, content)
.ContinueWith(async responseTask =>
{
var responseBody = await responseTask.Result
.Content.ReadAsStringAsync();
txtFaceList.Text = responseBody.ToString();
});
}// end of using statement
}
应该发生什么是HTTP动词状态OK 200应该返回,我得到的只是
{ "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } }
我看看我以前的帖子应用相同的方法,它只是不起作用。除了跳下屋顶,有人能指出正确的方向。
谢谢
答案 0 :(得分:2)
你有错误的HTTP动词。在这个case中你想使用POST,而不是PUT。因此,您需要将客户端调用更改为:
await client.PostAsync(uri, content)
.ContinueWith(async responseTask =>
{
var responseBody = await responseTask.Result.Content.ReadAsStringAsync();
txtFaceList.Text = responseBody.ToString();
});