Jquery Ajax API错误:400错误请求
我正在尝试使用Jquery向一个名为Cloudsight的图像识别API发出一个Ajax POST请求。到目前为止,我的代码是:Jquery Ajax API错误:400错误请求
$.ajax({
type: "POST",
url: "http://api.cloudsightapi.com/image_requests",
Authorization: "CloudSight [key]",
data: {
remote_image_url: "https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
locale: "en-US"
},
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
当我尝试运行它,我得到的错误:400(无效请求),我在做什么错?据我所看到的代码似乎是好的...
万一别人看这个,管理使用此代码来解决这个问题:
$.ajax({
method: "POST",
url: "https://api.cloudsightapi.com/image_requests",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "CloudSight [key]");
},
data: {
"image_request[remote_image_url]": "https://www.google.co.uk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
"image_request[locale]": "en-US"
},
success: function(msg) {
console.log("It worked! :D Good POST request.");
console.log(msg);
console.log(msg.token);
console.log(msg.url);
console.log(msg.responseText);
token = msg.token;
},
error: function(msg) {
console.log("Sorry...");
console.log(msg);
console.log(msg.responseText);
}
});
感谢马里奥切扎尔他与授权的帮助!
你应该接受你的答案,而不是我的答案。虽然我帮了你,但并没有为你提供完整的答案。 –
你有没有尝试过这样的事情?
beforeSend: function (req){
req.setRequestHeader("Authorization", "CloudSight [key]");
},
当我用冒号做这件事时,它给了我一个语法错误,但是如果我添加一个逗号(而不是正确的语法?),它会给我和以前一样的错误... – teamshortcut
确实是一个逗号。我会解决它。 –
很高兴知道,但我仍然收到400错误请求错误。任何其他想法? :/ – teamshortcut
我得到了:{{error:“收到非OAuth请求”} – Hackerman
您是否使用cloudscape API文档进行过验证,提供了所有必要的字段?我似乎无法访问它,所以我不能确定我自己。 – hughjidette
该网址可能存在问题。 – Aditya