Javascript 通过json访问URL,可以通过提供User/Pass在chrome中打开该URL
我可以通过访问以下地址在chrome中打开API url:Javascript 通过json访问URL,可以通过提供User/Pass在chrome中打开该URL,javascript,json,http,security,authentication,Javascript,Json,Http,Security,Authentication,我可以通过访问以下地址在chrome中打开API url: http://some-path-to-server.com/myapi/ 它需要一个用户/pw 登录后,我可以看到json响应。问题是如何在本地主机服务器中通过$.getJSON api调用获取json?或者我如何在getJSON调用中找到需要发送的额外参数。只需在javascript中调用$.getJSONapi即可 function getJson(){ $.getJSON("your url", function(da
http://some-path-to-server.com/myapi/
它需要一个用户/pw
登录后,我可以看到json响应。问题是如何在本地主机服务器中通过$.getJSON api调用获取json?或者我如何在getJSON调用中找到需要发送的额外参数。只需在javascript中调用
$.getJSON
api即可
function getJson(){
$.getJSON("your url", function(data){
alert("JSON Data: " + JSON.stringify(data));
});
}
Upd:您可以在如下代码的标题中添加授权信息。或者使用beforeSend
功能向标题添加额外信息
$.ajax({
type: "get",
url: "your url",
dataType: "json",
headers: {
"Authorization": "Bearer 5c530532-f39c-4f22-b48c-e226f8d08405"
},
success: function(result) {
console.log(result);
}
})
只需在javascript中调用
$.getJSON
api
function getJson(){
$.getJSON("your url", function(data){
alert("JSON Data: " + JSON.stringify(data));
});
}
Upd:您可以在如下代码的标题中添加授权信息。或者使用beforeSend
功能向标题添加额外信息
$.ajax({
type: "get",
url: "your url",
dataType: "json",
headers: {
"Authorization": "Bearer 5c530532-f39c-4f22-b48c-e226f8d08405"
},
success: function(result) {
console.log(result);
}
})
检查浏览器开发人员工具的“网络”选项卡。确保设置为“页面加载时不清除日志”,然后尝试访问该页面。鉴于您看到的是登录提示,几乎可以肯定它使用的是基本的HTTP授权:检查browser developer tools的network选项卡。确保设置为“页面加载时不清除日志”,然后尝试访问该页面。如果您看到登录提示,几乎可以肯定它使用的是基本HTTP授权:401授权失败您应该在HTTP头中添加授权信息。401授权失败您应该在HTTP头中添加授权信息。