我尝试使用Angular的HttpClient发送带有授权标头的请求,但标头未成功设置 .

在这里我的代码 .

loginGetToken(auth: Auth) {
    const url = `${this.config.uri}oauth/token`;
    const params = new HttpParams();
    // .set('grant_type', 'password')
    // .set('scope', 'all')
    // .set('redirect_uri', 'ws.28ph.cn')
    // .set('username', auth.username)
    // console.log(this.Authorization.token);
    //     .set('password', auth.password);
    return this.httpclient.post(url, JSON.stringify(auth), {headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': this.Authorization.token
    }, params: params})
    .subscribe(
        result => {
            console.log('result:' + result);
        },
        (error: HttpErrorResponse) => {
            console.log(error.error);
        }
    );
}

浏览器信息

Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: http://127.0.0.1:4200
Access-Control-Max-Age: 3600
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 0
Date: Sat, 06 Oct 2018 09:11:39 GMT
Expires: 0
Pragma: no-cache
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
WWW-Authenticate: Basic realm="oauth2/client"
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Provisional headers are shown
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Origin: http://127.0.0.1:4200

User-Agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,类似Gecko)Chrome / 69.0.3497.100 Safari / 537.36