【问题标题】:Angular automatically changes the http to https to load resourceAngular 自动将 http 更改为 https 以加载资源
【发布时间】:2020-10-13 07:39:17
【问题描述】:

在我的 Angular 应用程序中,所有 HTTP 资源在获取时都会自动更改为 https。我检查了服务器,并没有为 https 配置自动重定向设置。

以下是我在控制台和网络选项卡中遇到的错误。

core.js:3864 ERROR 
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http://xxxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub/", ok: false, …}
error: ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
message: "Http failure response for http://xxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub/: 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: "http://xxxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub/"
__proto__: HttpResponseBase

在控制台中显示的是 HTTP,但在网络选项卡中显示的是 HTTPS。

请求代码

constructor(private http: HttpClient) { }
     
 getHub( ): Observable<Hub> {
       
        return this.http.get<Hub>("http://xxxxxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub" );
      }

【问题讨论】:

  • 看不到截图,能否将错误信息分享为文字?
  • @shadowman_93 我用控制台中的错误文本编辑了描述。
  • 请检查你的IIS配置,你有这样的配置吗? stackoverflow.com/a/38686154/5955138
  • 不,我没有任何这样的配置
  • 在此处添加您的请求代码,没有代码我无法帮助您。

标签: angular angular-http


【解决方案1】:
getHub(): Observable<Hub> {  
  return this.http.get<Hub>("http://xxxxxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub" ).subscribe(test => console.log(test));
  }

试试看,看看你的期望。

【讨论】:

  • 它无法订阅响应,因为它由于 URL 上的 https 而失败。我订阅了错误状态,下面给出了异常。它与我在浏览器 HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http://xxxx-env.eba-prmacaby.ap-south-1. elasticbeanstalk.com/all/hub/",好的:假,...}
  • 你在app.module.ts中添加了HttpClientModule
  • 是的,没有与代码相关的异常。我的其他 HTTPS 资源加载正常。
  • 尝试去掉Observable,写一个纯方法。 getHub() { return this.http.get("http://xxxxxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub"); } 看看它是否有效并删除all/hub 末尾的空白,因为你那里有一个空间。
猜你喜欢
  • 2020-12-30
  • 2012-02-24
  • 2021-07-31
  • 2016-07-10
  • 1970-01-01
  • 2015-03-25
  • 2018-01-02
  • 2018-05-22
相关资源
最近更新 更多