未找到资源 Face API 1.0
Resource not found Face API 1.0
为了我一生的挚爱,我只是想不通为什么我的 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 应该 return 返回,我得到的只是
{ "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } }
我查看了我以前的 post 应用了相同的方法,但它不起作用。除了跳下屋顶,有人能给我指出正确的方向吗?
谢谢
您的 HTTP 动词有误。在此 case 中,您要使用 POST,而不是 PUT。因此,您需要将客户端调用更改为:
await client.PostAsync(uri, content)
.ContinueWith(async responseTask =>
{
var responseBody = await responseTask.Result.Content.ReadAsStringAsync();
txtFaceList.Text = responseBody.ToString();
});
为了我一生的挚爱,我只是想不通为什么我的 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 应该 return 返回,我得到的只是
{ "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } }
我查看了我以前的 post 应用了相同的方法,但它不起作用。除了跳下屋顶,有人能给我指出正确的方向吗?
谢谢
您的 HTTP 动词有误。在此 case 中,您要使用 POST,而不是 PUT。因此,您需要将客户端调用更改为:
await client.PostAsync(uri, content)
.ContinueWith(async responseTask =>
{
var responseBody = await responseTask.Result.Content.ReadAsStringAsync();
txtFaceList.Text = responseBody.ToString();
});