HttpClient POST解析为域主机IP而不是API IP

时间:2018-10-07 17:44:29

标签: angular azure google-chrome zonejs

当前行为

目前,我在有 151.101.1.195 的Firebase托管中托管angular 并且我的API位于具有IP 23.98.64.158

的azure服务器上

然后我在我的角度v6.1.7中使用以下几行发送POST请求

const req = new HttpRequest('POST', `${environment.ApiHost}api/do/something`, token, { headers: this.authenticationService.getAccessTokenHeader(), responseType: "text" });
return this.httpClient.request<any>(req);

它假设要在 23.98.64.158 处对我的Azure API服务器执行OPTIONS请求,然后仅进行POST 但是不知何故,它先后发布,选择和发布。 查看chrome devtool的“网络”标签,显示我的请求针对第一个POST转到了Firebase ip 151.101.1.195 (但不应这样做),但随后的OPTION和POST请求解决了以纠正Azure IP 23.98.64.158

这是我抓到的我的devtool标头常规信息,表明它发布到错误的Remote Address 151.101.1.195

Request URL: https://someazuresite.azurewebsites.net/api/do/something
Request Method: POST
Status Code: 504 Gateway Timeout (from ServiceWorker)
Remote Address: 151.101.1.195:443
Referrer Policy: no-referrer-when-downgrade

FROM INITIATOR:-
m | @ | zone.js.pre-build-optimizer.js:2969
-- | -- | --
  | t.scheduleTask | @ | zone.js.pre-build-optimizer.js:407
  | onScheduleTask | @ | zone.js.pre-build-optimizer.js:297
  | t.scheduleTask | @ | zone.js.pre-build-optimizer.js:401
  | e.scheduleTask | @ | zone.js.pre-build-optimizer.js:232
  | e.scheduleMacroTask | @ | zone.js.pre-build-optimizer.js:255
  | p | @ | zone.js.pre-build-optimizer.js:1114
  | (anonymous) | @ | zone.js.pre-build-optimizer.js:3001
  | N.o.(anonymous function) | @ | zone.js.pre-build-optimizer.js:1394
  | (anonymous) | @ | http.js.pre-build-optimizer.js:1639
  | e._trySubscribe | @ | Observable.js.pre-build-optimizer.js:42
  | e.subscribe | @ | Observable.js.pre-build-optimizer.js:28
  | e.call | @ | catchError.js.pre-build-optimizer.js:18
  | e.subscribe | @ | Observable.js.pre-build-optimizer.js:23
  | (anonymous) | @ | subscribeTo.js.pre-build-optimizer.js:21
  | i | @ | subscribeToResult.js.pre-build-optimizer.js:11
  | t._innerSub | @ | mergeMap.js.pre-build-optimizer.js:73
  | t._tryNext | @ | mergeMap.js.pre-build-optimizer.js:68
  | t._next | @ | mergeMap.js.pre-build-optimizer.js:51
  | t.next | @ | Subscriber.js.pre-build-optimizer.js:55
  | (anonymous) | @ | scalar.js.pre-build-optimizer.js:5
  | e._trySubscribe | @ | Observable.js.pre-build-optimizer.js:42
  | e.subscribe | @ | Observable.js.pre-build-optimizer.js:28
  | e.call | @ | mergeMap.js.pre-build-optimizer.js:29
  | e.subscribe | @ | Observable.js.pre-build-optimizer.js:23
  | (anonymous) | @ | kg-fcm-setup.component.ts:64

然后随后的请求指向正确的Azure IP

Request URL: https://someazuresite.azurewebsites.net/api/do/something
Request Method: OPTIONS
Status Code: 200 OK
Remote Address: 23.98.64.158:443
Referrer Policy: no-referrer-when-downgrade

Request URL: https://someazuresite.azurewebsites.net/api/do/something
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: 23.98.64.158:443
Referrer Policy: no-referrer-when-downgrade

预期行为

我应该只看到调用OPTION和POST到https://someazuresite.azurewebsites.net/api/do/something并解析为仅AZURE IP 远程地址:23.98.64.158:443 为什么zone.js会启动POST到错误的Firebase IP?

通过说明将问题最小化

改变行为的动机/用例是什么?

环境

Angular CLI: 6.1.5
Node: 8.12.0
OS: win32 x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.7.1
@angular-devkit/build-angular      0.7.1
@angular-devkit/build-ng-packagr   0.7.5
@angular-devkit/build-optimizer    0.7.1
@angular-devkit/build-webpack      0.7.1
@angular-devkit/core               0.7.5
@angular-devkit/schematics         0.7.5
@angular/cli                       6.1.5
@angular/pwa                       0.7.5
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.1.1
@schematics/angular                0.7.5
@schematics/update                 0.7.5
ng-packagr                         3.0.6
rxjs                               6.3.2
typescript                         2.9.2
webpack                            4.9.2
<pre><code>
Angular version: X.Y.Z
<!-- Check whether this is still an issue in the most recent Angular version -->

Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
```

For Tooling issues:
- Node version: v8.12.0
- Platform:  windows 10 Version 10.0.17134 Build 17134

2 个答案:

答案 0 :(得分:0)

当我使用HttpClient时,我在构造函数中设置为私有对象,然后以这种方式在函数中使用该对象:

`构造函数(私有http:HttpClient){}

request(token){     返回this.http.post(this.URLAPI / any,令牌); }`

也许这会有所帮助。

答案 1 :(得分:0)

您的问题与Angular无关,而与域设置无关。

您的域的DNS似乎最近已更改。只需等待24-48小时即可永久看到更改。