-1

I need some help, I don't know how but all my http.put and http.delete request from my angular's client are changing in http.options. The only error that I have is:

ERROR Object { headers: Object, status: 0, statusText: "Unknown Error", url: null, ok: false, name: "HttpErrorResponse", message: "Http failure response for (unknown …", error: error }

If someone has an idea, thanks to answer me.

Have a nice day

let header = new HttpHeaders({
      'Access-Control-Allow-Credentials':'true',
      'Access-Control-Allow-Origin' : '*',
      'Access-Control-Allow-Headers' : 'Origin, X-Requested-With, Content-Type, Accept'
  });
  this.http
          .put('http://localhost:1993/pays/'+this.codeNouveauPays, JSON.stringify(""), {
                headers : header,
                params : new HttpParams().set('nom', this.nomNouveauPays).set('code', this.codeNouveauPays)
            })
          .subscribe();

1 Answers1

0

Your requests are not changed to OPTIONS requests, that's the preflight request

The error you get is because your server (your API) has an error when receiving the preflight request.

Because the preflight request fails, your actual request (DELETE or PUT) on the same endpoint is never done.

A solution to implement preflight handling in jersey can be found here.

Supamiu
  • 8,501
  • 7
  • 42
  • 76
  • I try it, and it doesn't work – Tobias Zelft Jul 27 '17 at 15:26
  • @TobiasZelft — Then (1) Use the Network tab to look at exactly what requests and responses are being made (2) Figure out which one of the requests is getting the wrong response (3) Look at the (server side!) code you wrote to make that response and try to fix it (4) Failing that, ask a new question with a [mcve] – Quentin Jul 27 '17 at 15:42