xmlHttprequest getting called with “OPTIONS” method only












0















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
    Nov 19 '18 at 10:26











  • 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: *.

    – Harsimer
    Nov 19 '18 at 11:56
















0















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
    Nov 19 '18 at 10:26











  • 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: *.

    – Harsimer
    Nov 19 '18 at 11:56














0












0








0








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 Nov 19 '18 at 12:01







Harsimer

















asked Nov 19 '18 at 9:34









HarsimerHarsimer

92131443




92131443








  • 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
    Nov 19 '18 at 10:26











  • 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: *.

    – Harsimer
    Nov 19 '18 at 11:56














  • 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
    Nov 19 '18 at 10:26











  • 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: *.

    – Harsimer
    Nov 19 '18 at 11:56








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
Nov 19 '18 at 10:26





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
Nov 19 '18 at 10:26













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: *.

– Harsimer
Nov 19 '18 at 11:56





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: *.

– Harsimer
Nov 19 '18 at 11:56












0






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',
autoActivateHeartbeat: false,
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

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?