Issue
I am trying to send a post request using HttpClient.
constructor (private http: HttpClient) { }
this.http.post(url + 'auth/login', data).subscribe(res => { });
but the browser sends 4 requests instead of only one POST request:
- 2 OPTIONS requests
- 1 POST request
- 1 GET request
I have read that it's called "preflight request" https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests
I am getting a 405 Method Not Allowed error because the server do not support GET requests for this path The GET method is not supported for this route. Supported methods: POST.
Unfortianatilly, I cannot modify the server to accept GET requests, is there anyway that I can prevent the browser from sending a GET request?
Thanks in advance.
Solution
I figured out that this happens only on "http://".
I have tried "https://" and it works correctly :)
Answered By - Yousef Aburayyan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.