javascript authenticate with htpasswd and fetch json

天大地大妈咪最大 提交于 2021-01-27 19:05:11

问题


I have an API that generates json, problem is its password protected url, using Apache htpasswd.

how can I authenticate and retrieve the json from javascript, since all methods I have tried give me access deined (I've been using http://username:passwd@urldotcom/path/to/stuff)

Thanks


回答1:


I figured out how to do it.

 var something = jQuery.ajax({
    type: "GET",
    url: url,
    username: "user",
    password: "password"    
});

url is a variable I declared earlier of format http:///path/to/json



来源:https://stackoverflow.com/questions/38458331/javascript-authenticate-with-htpasswd-and-fetch-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!