0

当前行为

目前我在具有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,但不知何故它会先 POST、OPTION 然后 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 only Remote Address: 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
4

2 回答 2

0

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

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

于 2018-10-08T20:46:54.457 回答
0

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

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

request(token) { return this.http.post(this.URLAPI/any, token); }`

也许这会有所帮助。

于 2018-10-07T19:10:50.423 回答