2017-06-09 62 views
3

我正在使用Microsoft Face API来构建使用Electron的面部识别桌面应用程序。现在我可以检测人脸,并创建一个个人组,但遇到这样的错误,当我尝试和一个人添加到我的人团:Microsoft Face API - 400请求正文无效

{"error":{"code":"BadArgument","message":"Request body is invalid."}}, 

其标记为我的控制台上的错误400错误请求。

这是API页关于如何使用这个请求:

这里是我的代码,明明事情是错误的数据字段,但是当我在westCentralUS测试服务器使用相同的数据,这是成功的。我尝试过使用并省略了可选的userData字段,包含一个字符串和一个图像文件。

function createPerson() { 

var params = { 
     // Request parameters 
    }; 

    $.ajax({ 
     url: "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/persongroups/students/persons", 
     beforeSend: function(xhrObj){ 
      // Request headers 
      xhrObj.setRequestHeader("Content-Type","application/json"); 
      xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key",apiKey); 
     }, 
     type: "POST", 
     // Request body 
     data: { name: "John",} 
    }) 
    .done(function(data) { 
     alert("success"); 
    }) 
    .fail(function() { 
     alert("error"); 
    }); 
} 

回答

4

尝试

data: JSON.stringify({name: "John"}) 

代替。

+0

谢谢!就是这样。我知道这是一件小事。 –

+0

@RahulJobanputra你应该将此标记为接受的答案:) –

相关问题