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:





  1. 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

  2. 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!










share|improve this question




















  • 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















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:





  1. 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

  2. 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!










share|improve this question




















  • 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













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:





  1. 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

  2. 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!










share|improve this question















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:





  1. 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

  2. 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$