Martin Eckleben
Martin Eckleben

Reputation: 802

Angular 7 not sending HttpClient POST request - instead dying with "Unknown Error"

EDIT3: SOLUTION after hours:
Firefox extension uBlock blocked the request (probably because it contained adverts)
Lesson learned: always check in a private tab!

I Really run out of ideas and appreciate every bit of advice :)

EDIT:
For intuitivity:
Im sending two POST requests
/api/adverts/search which does not even show up in Firefox network tab.
and
/api/marketplacecategories/get which returns successfull with 200

EDIT2:
The same request from a fresh angular app works

Sending the request:

  let options = {
     'headers' : {
        'accept': 'application/json'
     }
  }
  let data = new FormData()
  this.http.post("/api/adverts/search",data, options)
  .subscribe(
     data => {
        console.log("success")
        console.log(data)
     }
  );

Angular is not sending the request:

enter image description here

But instead giving me an error in the js console:

enter image description here

Meanwhile the other POST request to the same api is working just fine.

Postman to the same url works just fine:

enter image description here

CORS headers are set by server globally and work just fine for the other successfull request:

enter image description here

Does anyone have the slightest idea?
Im quite desperate :D

Upvotes: 1

Views: 2113

Answers (2)

Martin Eckleben
Martin Eckleben

Reputation: 802

Firefox uBlock Origin extension blocked the request
probably because it contained adverts.

Lesson learned: always check in a private tab!

Solved.

Thank you all very much for your time and advice!

Upvotes: 1

Adrita Sharma
Adrita Sharma

Reputation: 22213

You need to add the full url like:

this.http.post("http://192.168.56.11:2503/api/adverts/search",data, options)

You should store the common port in environment.ts

apiUrl: "http://192.168.56.11:2503"

and then,

this.http.post(`${environment.apiUrl}/api/adverts/search`,data, options)

Upvotes: 0

Related Questions