Angular 7 POST-基本授权不起作用

时间:2019-07-10 16:38:48

标签: angular7 basic-authentication

这是我的POST请求:

let authorizationData = 'Basic ' + btoa('username' + ':' + 'password');

    const headerOptions = {
        headers: new HttpHeaders({
            'Content-Type':  'application/json; charset=utf-8',
            'Authorization': authorizationData
        })
    };
    return this.http.post(URL, {}, headerOptions);

从Postman击中相同的URL效果很好,但是在应用程序中,我得到了:

POST 'URL' 400 (Bad Request)

请求标头如下:

Host: localhost
Connection: keep-alive
Content-Length: 2
Accept: application/json, text/plain, */*
Origin: https://localhost
Authorization: Bearer
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Content-Type: application/json; charset=UTF-8
Referer: https://localhost/dist/login?returnUrl=%2Fhome
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,ru;q=0.8,fr-FR;q=0.7,fr;q=0.6,de;q=0.5
Cookie: _ga=GA1.1.1572233673.1553008118; ai_user=lKLiD|2019-05- 
08T14:05:22.062Z; ASP.NET_SessionId=e5qyhmtg13ujthsahyloi2bx

不知道它是对还是错,但是授权看起来不正确或者是? 请帮忙。

谢谢

0 个答案:

没有答案