2

In my angular app, all the HTTP resources are automatically changed to https while fetching. I checked the server, and there are no automatic redirect settings configured to https.

The following are the errors I get in the console and the network tab.

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

enter image description here

enter image description here In the console it says HTTP but in the network tab, it says HTTPS.

Request Code

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

2 Answers2

0
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));
  }

Try it and show what are u expecting.

TheCoderGuy
  • 771
  • 6
  • 24
  • 51
  • It can't subscribe to the response as it fails due to the https on the URL. I subscribed to the error state and the exception is given below. It is the same as the exception I see on the browser HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http:// xxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub/", ok: false, …} – Vishnu S Kumar Oct 13 '20 at 13:55
  • Have you added the HttpClientModule in the `app.module.ts` – TheCoderGuy Oct 13 '20 at 14:20
  • Yes, there is no exception related to the code. My other HTTPS resources are loading fine. – Vishnu S Kumar Oct 13 '20 at 14:50
  • Try to remove the `Observable` and write a pure method. `getHub() { return this.http.get("http://xxxxxxxx-env.eba-prmacaby.ap-south-1.elasticbeanstalk.com/all/hub"); }` Look if it works and remove the white space at the end of the `all/hub` because u have a space there. – TheCoderGuy Oct 13 '20 at 15:02
0

Please check your CSP there if you have "upgrade-insecure-requests" you are upgrading your http requests to https requests.

Do not use following content attribute:-

meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"

Akshay
  • 1
  • 1