簡體   English   中英

Angular HttpClient 無法得到響應

[英]Angular HttpClient cannot get response

我沒有得到任何服務器對此發布請求的響應:

 this.httpClient
            .post(this.appConfigService.buildAuthorizationUrl('/logon'), data, {
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                //observe: 'response',
            })
            .toPromise()
            .then(
                (response: any) => {
                                // not reached
                },
                (error: any) => {
                                // not reached
                }
            )
            .catch(ex => {
               // not reached
            });

更新:提琴手顯示了我希望在.then成功塊中獲得的服務器響應:

服務器響應示例:

HTTP/1.1 400 Bad Request
Cache-Control: no-cache,no-cache, no-store, must-revalidate
Pragma: no-cache,no-cache
Content-Type: application/json;charset=UTF-8
Expires: -1,0
Server: Microsoft-IIS/10.0
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcS2F5IFphbmRlclxEb2N1bWVudHNcZXZlXFNvdXJjZVxJbmZvcnNIVC5HZW5lc2lzQXBpXGxvZ29u?=
X-Powered-By: ASP.NET
X-UA-Compatible: IE=edge
Date: Wed, 30 Oct 2019 10:33:16 GMT
Content-Length: 79

{"error":"Error","error_description":"The user name or password is incorrect."}

UPDATE可能是因為標題

Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors

代替

Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors

背景:我正在將現有 angularjs 應用程序遷移到 angular 並且我使用相同(未更改)API

問題是由 CORS 問題引起的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM