2017-06-09 63 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你應該將此標記爲接受的答案:) –

相關問題