我正在尝试使用postmates ,它首先要求我们使用http身份验证。下面代码中的username字段是我们插入private API key的地方。
<script>
$(document).ready(function(){
// Request with custom header
$.ajax({
url: ' http://username:@api.postmates.com',
type: 'GET',
dataType: 'jsonp',
success: function(response) { alert("Success"); },
error: function(error) {alert(error); }
});
});
</script>我们所犯的错误是
XMLHttpRequest无法加载=1462052396725。飞行前的响应无效(重定向)
发布于 2016-04-30 22:04:37
需要认证
https://postmates.com/developer/docs#authentication
实际使用的标题将是一个base64 64编码的字符串,如下所示: 基本Y2YyZjJkNmQtYTMxNC00NGE4LWI2MDAtNTA1M2MwYWYzMTY1Og==
试着
$(document).ready(function(){
// Request with custom header
$.ajax({
url: ' http://username:@api.postmates.com',
type: 'GET',
dataType: 'jsonp',
success: function(response) { alert("Success"); },
error: function(error) {alert(error); },
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic Y2YyZjJkNmQtYTMxNC00NGE4LWI2MDAtNTA1M2MwYWYzMTY1Og==");
}
});
});我不测试是因为胡作非为阻碍了外界的请愿。
https://stackoverflow.com/questions/36960660
复制相似问题