xmlHttprequest getting called with “OPTIONS” method only
up vote
0
down vote
favorite
I make a request to server (an API call) from one server and it is cross-origin resource so I expect options request.
For option request I am getting below response headers:
access-control-allow-headers: 'all headers I sent'
access-control-allow-methods: GET,OPTIONS
access-control-allow-origin: *
content-length: 0
content-type: application/json
date: Mon, 19 Nov 2018 09:14:32 GMT
status: 200
x-amz-apigw-id: some id
x-amzn-requestid: 'some id'
When response header is returning:
access-control-allow-origin: *
I get an error:
Access to XMLHttpRequest at
'APIURL' from origin 'http://localhost:4200' has been blocked by CORS policy:
Request header field X-Application is not allowed by
Access-Control-Allow-Headers in preflight response.
Then why request with method was not made?
Whereas another API to same server with same response for options request work with get method.
I am using angular7 and backend servers has enabled CORS.
Can someone guide me why this is happening, what changes I can make?
Thanks!
UPDATE:
I removed X-APPLICATION header from request headers as per comment from "sideshowbarker". But still get below error below error for 2 API, whereas others API from same origin to same server works fine:
- Access to XMLHttpRequest at 'APIURL server 1' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. -- Server1 from local host
- Access to XMLHttpRequest at
'API URL server2'
from origin 'http://localhost:4200' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
If server is configured to handle CROSS origin request then I should not get this error. I will grateful if someone help me understand and solve this.
If someone wants to help, let me know if more details are required.
Thanks!
http cors
add a comment |
up vote
0
down vote
favorite
I make a request to server (an API call) from one server and it is cross-origin resource so I expect options request.
For option request I am getting below response headers:
access-control-allow-headers: 'all headers I sent'
access-control-allow-methods: GET,OPTIONS
access-control-allow-origin: *
content-length: 0
content-type: application/json
date: Mon, 19 Nov 2018 09:14:32 GMT
status: 200
x-amz-apigw-id: some id
x-amzn-requestid: 'some id'
When response header is returning:
access-control-allow-origin: *
I get an error:
Access to XMLHttpRequest at
'APIURL' from origin 'http://localhost:4200' has been blocked by CORS policy:
Request header field X-Application is not allowed by
Access-Control-Allow-Headers in preflight response.
Then why request with method was not made?
Whereas another API to same server with same response for options request work with get method.
I am using angular7 and backend servers has enabled CORS.
Can someone guide me why this is happening, what changes I can make?
Thanks!
UPDATE:
I removed X-APPLICATION header from request headers as per comment from "sideshowbarker". But still get below error below error for 2 API, whereas others API from same origin to same server works fine:
- Access to XMLHttpRequest at 'APIURL server 1' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. -- Server1 from local host
- Access to XMLHttpRequest at
'API URL server2'
from origin 'http://localhost:4200' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
If server is configured to handle CROSS origin request then I should not get this error. I will grateful if someone help me understand and solve this.
If someone wants to help, let me know if more details are required.
Thanks!
http cors
1
The 'APIURL' server/endpoint needs to be configured to include 'X-Application' in the access-control-allow-headers value. It’s not currently configured to do that. Otherwise you wouldn’t be getting that error message.
– sideshowbarker
8 hours ago
Thaks @sideshowbarker for help. I removed that header and that error went away. What if I don't get "Access to XMLHttpRequest at 'APIURL' from origin 'localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. " whereas server returns access-control-allow-origin: *.
– Simer
7 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I make a request to server (an API call) from one server and it is cross-origin resource so I expect options request.
For option request I am getting below response headers:
access-control-allow-headers: 'all headers I sent'
access-control-allow-methods: GET,OPTIONS
access-control-allow-origin: *
content-length: 0
content-type: application/json
date: Mon, 19 Nov 2018 09:14:32 GMT
status: 200
x-amz-apigw-id: some id
x-amzn-requestid: 'some id'
When response header is returning:
access-control-allow-origin: *
I get an error:
Access to XMLHttpRequest at
'APIURL' from origin 'http://localhost:4200' has been blocked by CORS policy:
Request header field X-Application is not allowed by
Access-Control-Allow-Headers in preflight response.
Then why request with method was not made?
Whereas another API to same server with same response for options request work with get method.
I am using angular7 and backend servers has enabled CORS.
Can someone guide me why this is happening, what changes I can make?
Thanks!
UPDATE:
I removed X-APPLICATION header from request headers as per comment from "sideshowbarker". But still get below error below error for 2 API, whereas others API from same origin to same server works fine:
- Access to XMLHttpRequest at 'APIURL server 1' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. -- Server1 from local host
- Access to XMLHttpRequest at
'API URL server2'
from origin 'http://localhost:4200' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
If server is configured to handle CROSS origin request then I should not get this error. I will grateful if someone help me understand and solve this.
If someone wants to help, let me know if more details are required.
Thanks!
http cors
I make a request to server (an API call) from one server and it is cross-origin resource so I expect options request.
For option request I am getting below response headers:
access-control-allow-headers: 'all headers I sent'
access-control-allow-methods: GET,OPTIONS
access-control-allow-origin: *
content-length: 0
content-type: application/json
date: Mon, 19 Nov 2018 09:14:32 GMT
status: 200
x-amz-apigw-id: some id
x-amzn-requestid: 'some id'
When response header is returning:
access-control-allow-origin: *
I get an error:
Access to XMLHttpRequest at
'APIURL' from origin 'http://localhost:4200' has been blocked by CORS policy:
Request header field X-Application is not allowed by
Access-Control-Allow-Headers in preflight response.
Then why request with method was not made?
Whereas another API to same server with same response for options request work with get method.
I am using angular7 and backend servers has enabled CORS.
Can someone guide me why this is happening, what changes I can make?
Thanks!
UPDATE:
I removed X-APPLICATION header from request headers as per comment from "sideshowbarker". But still get below error below error for 2 API, whereas others API from same origin to same server works fine:
- Access to XMLHttpRequest at 'APIURL server 1' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. -- Server1 from local host
- Access to XMLHttpRequest at
'API URL server2'
from origin 'http://localhost:4200' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: It
does not have HTTP ok status.
If server is configured to handle CROSS origin request then I should not get this error. I will grateful if someone help me understand and solve this.
If someone wants to help, let me know if more details are required.
Thanks!
http cors
http cors
edited 7 hours ago
asked 9 hours ago
Simer
91531338
91531338
1
The 'APIURL' server/endpoint needs to be configured to include 'X-Application' in the access-control-allow-headers value. It’s not currently configured to do that. Otherwise you wouldn’t be getting that error message.
– sideshowbarker
8 hours ago
Thaks @sideshowbarker for help. I removed that header and that error went away. What if I don't get "Access to XMLHttpRequest at 'APIURL' from origin 'localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. " whereas server returns access-control-allow-origin: *.
– Simer
7 hours ago
add a comment |
1
The 'APIURL' server/endpoint needs to be configured to include 'X-Application' in the access-control-allow-headers value. It’s not currently configured to do that. Otherwise you wouldn’t be getting that error message.
– sideshowbarker
8 hours ago
Thaks @sideshowbarker for help. I removed that header and that error went away. What if I don't get "Access to XMLHttpRequest at 'APIURL' from origin 'localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. " whereas server returns access-control-allow-origin: *.
– Simer
7 hours ago
1
1
The 'APIURL' server/endpoint needs to be configured to include 'X-Application' in the access-control-allow-headers value. It’s not currently configured to do that. Otherwise you wouldn’t be getting that error message.
– sideshowbarker
8 hours ago
The 'APIURL' server/endpoint needs to be configured to include 'X-Application' in the access-control-allow-headers value. It’s not currently configured to do that. Otherwise you wouldn’t be getting that error message.
– sideshowbarker
8 hours ago
Thaks @sideshowbarker for help. I removed that header and that error went away. What if I don't get "Access to XMLHttpRequest at 'APIURL' from origin 'localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. " whereas server returns access-control-allow-origin: *.
– Simer
7 hours ago
Thaks @sideshowbarker for help. I removed that header and that error went away. What if I don't get "Access to XMLHttpRequest at 'APIURL' from origin 'localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. " whereas server returns access-control-allow-origin: *.
– Simer
7 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371766%2fxmlhttprequest-getting-called-with-options-method-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The 'APIURL' server/endpoint needs to be configured to include 'X-Application' in the access-control-allow-headers value. It’s not currently configured to do that. Otherwise you wouldn’t be getting that error message.
– sideshowbarker
8 hours ago
Thaks @sideshowbarker for help. I removed that header and that error went away. What if I don't get "Access to XMLHttpRequest at 'APIURL' from origin 'localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. " whereas server returns access-control-allow-origin: *.
– Simer
7 hours ago