【发布时间】:2018-08-08 21:50:19
【问题描述】:
我正在尝试调用 AngularJS 中的 API。 API 有 HTTP Basic Authentication 和 username = admin 和 password = admin123
这就是我调用 API 的方式,
$http.get('https://example.com', {
headers: {'Authorization': 'Basic YWRtaW46YWRtaW4xMjM='}
}).then(console.log("something"));
但是,它给了我401 UnAuthorized 的响应。传递用户名和密码的推荐方式是什么?我正在使用AngularJS 1。
显示错误,
OPTIONS https://example.com 401 ()
Failed to load https://example.com: Response for preflight has invalid HTTP status code 401.
Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","headers":{"Authorization":"Basic YWRtaW46YWRtaW4xMjM=","Accept":"application/json, text/plain, */*"},"url":"https://example.com"},"statusText":"","xhrStatus":"error"}
【问题讨论】:
标签: javascript angularjs http basic-authentication