我在访问http rest api具有基本身份验证机制的应用程序上具有单一登录。 以下是API的请求和响应标头:
General
Request URL: https://10.x.x.x8/piwebapi/
Request Method: GET
Status Code: 401 Unauthorized
Remote Address: 10.10.x.x.x8
Referrer Policy: no-referrer-when-downgrade
Response Headers
Content-Length: 0
Date: Mon, 10 Sep 2018 12:57:50 GMT
Server: Microsoft-HTTPAPI/2.0
WWW-Authenticate: Negotiate
Request Headers
Provisional headers are shown
Accept: application/json, text/plain, */*
Access-Control-Allow-Origin: *
Authorization:
Content-Type: application/json
Origin: http://localhost:4200
Referer: http://localhost:4200/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
WWW-Authenticate: Basic
X-Requested-With: XMLHttpRequest
x-user-operation: true
X-XSRF-TOKEN: 3d794113-0d5c-4be7-848a-a73938b617cb
我正在使用以下代码处理401未经授权的错误:
getPiData(postUrl): Observable<any[]> {
let headersPi = new HttpHeaders();
headersPi = headersPi.append('Content-Type', 'application/json');
headersPi = headersPi.append("Authorization", 'Basic ' + btoa('XXX": XXX'));
headersPi = headersPi.append('Access-Control-Allow-Origin', '*');
headersPi = headersPi.append('WWW-Authenticate', 'Basic');
return this.http
.get(postUrl,{ headers: headersPi})
.map((response: Response) => {
this.logger.log("info", response);
//console.log('Response ', response);
return response
})
.catch(this.handleError);
}