我正在尝试从Handshake App获取项目列表作为XML。他们给了一些休息API。握手API帮助是here。
我遇到了身份验证问题。
他们说使用curl
$ curl -u 2c493d74:X https://app.handshake.com/api/v2/orders
我使用AJAX从服务器获取数据但仍然出现net::ERR_EMPTY_RESPONSE
错误。这是我的代码:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "https://app.handshake.com/api/v2/items.xml",
dataType: "xml",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
success: function (xml) {
console.log(xml);
}
});
});
我不确定是否应该使用username
+ password
或API key
+ x
。都没有工作。
答案 0 :(得分:0)
您的问题在这里:
cellForItemAtIndexPath
这使用btoa("username:password")
和username
作为字符串。如果这与您的代码中的相同,请更改此内容。
否则,您实际上需要使用password
和apiKey
。
来自文档:
握手API要求您使用HTTP基本身份验证来传递每个请求的API密钥。您应该将API密钥作为用户名传递给' X'作为密码。
您的代码应如下所示:
password