sf_2018
sf_2018

Reputation: 115

"Http failure response for (unknown url): 0 Unknown Error" Angular

I try use service httpClient post but I have this error:

enter image description here

code service:

constructor(private http:HttpClient) { }

              Login(data)
              {

                let headers: any = new HttpHeaders();
                headers.append('Content-Type', 'application/json');

                return this.http.post('link api',data,{headers: headers})
                .subscribe(res => console.log(res),err => { console.log(err);});

              }

and I try add responseType: 'text' but also error ... I use angular 4

Upvotes: 3

Views: 24863

Answers (2)

Kunal Tyagi
Kunal Tyagi

Reputation: 4197

In the backend code, If you are using Spring boot add an annotation @Crossorigin right above the CRUD API call method.

Upvotes: 0

Orodan
Orodan

Reputation: 1047

From what I can see, it's not an error from the http client directly, but from your server.

In a similar issue, the problem was coming from CORS and the fact that the Access-Control-Allow-Origin header was not correctly added in case the server response did not have a 20X or 30X status.

Did you check your server and log the call ?

Hope that helps

Upvotes: 4

Related Questions