Angular5 头请求未命中服务器的HttpClient或Http POST

Angular5 头请求未命中服务器的HttpClient或Http POST,angular5,angular-httpclient,Angular5,Angular Httpclient,我试图发出一个http请求来验证用户,作为响应,我需要获得服务器发出的令牌 这个ajax调用运行良好 但我需要它的角度,所以我尝试了以下两种方法,但都不起作用。 第一 第二 this.httpClient.post(“/token”, {'Id':“test”,'Password':“test”}, { headers:newhttpheaders({'Content-Type':'application/json'}), 观察:“回应” }); 它们有什么问题。 我使用的是DotnetCor

我试图发出一个http请求来验证用户,作为响应,我需要获得服务器发出的令牌

这个ajax调用运行良好 但我需要它的角度,所以我尝试了以下两种方法,但都不起作用。

第一 第二
this.httpClient.post(“/token”,
{'Id':“test”,'Password':“test”},
{
headers:newhttpheaders({'Content-Type':'application/json'}),
观察:“回应”
});
它们有什么问题。
我使用的是DotnetCore2.1和angular 5

请帮我解决这个问题。

你的方法是可以观察到的

为了发送请求并获得结果,您需要订阅它们

这是第二种方法的一个示例

this.httpClient.post<any>("/token",
                    { 'Id': "test", 'Password': "test" },
                    {
                        headers: new HttpHeaders({ 'Content-Type': 'application/json' })
                    }).subscribe(response => {
                           console.log("token =" + response);
                    });
this.httpClient.post(“/token”,
{'Id':“test”,'Password':“test”},
{
标题:新的HttpHeaders({'Content-Type':'application/json'})
}).订阅(响应=>{
console.log(“令牌=”+响应);
});

您的方法是可观察的

为了发送请求并获得结果,您需要订阅它们

这是第二种方法的一个示例

this.httpClient.post<any>("/token",
                    { 'Id': "test", 'Password': "test" },
                    {
                        headers: new HttpHeaders({ 'Content-Type': 'application/json' })
                    }).subscribe(response => {
                           console.log("token =" + response);
                    });
this.httpClient.post(“/token”,
{'Id':“test”,'Password':“test”},
{
标题:新的HttpHeaders({'Content-Type':'application/json'})
}).订阅(响应=>{
console.log(“令牌=”+响应);
});
this.httpClient.post<any>("/token",
            { 'Id': "test", 'Password': "test" },
            {
                headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
                observe: 'response'
            });
this.httpClient.post<any>("/token",
                    { 'Id': "test", 'Password': "test" },
                    {
                        headers: new HttpHeaders({ 'Content-Type': 'application/json' })
                    }).subscribe(response => {
                           console.log("token =" + response);
                    });