Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$http GET turns into OPTIONS #1585

Closed
alexeygolev opened this issue Nov 16, 2012 · 17 comments
Closed

$http GET turns into OPTIONS #1585

alexeygolev opened this issue Nov 16, 2012 · 17 comments

Comments

@alexeygolev
Copy link

Even taking all the client side and server side issues of CORS into account I'm still not managing to make it work.

This works

         $.ajax({
            type:"GET",
            url: "https://website.com/getProfile",
            xhrFields: {
               withCredentials: true
            },
            crossDomain: true
        }).done(function ( data ) {
              if( console && console.log ) {
              console.log(data);
            }
      });

however this doesn't

      $http.defaults.useXDomain = true;
      $http({
          method: "GET",
          url: "https://website.com/getProfile",
          withCredentials: true,
          }).success(
              function(data, status, headers, config) {
                console.log(data);
              }).error(function(data, status, headers, config) {
                console.log(data);
               });

The latter turns GET request into pending OPTIONS request. What am I missing? It can't be a bug can it?

@squeaky-pl
Copy link

I think it is not a place too ask such questions but anyway it would be very helpful if you provided the request headers and response headers for the OPTIONS request that is issued.

@alexeygolev
Copy link
Author

If I didn't think that it might be a bug I would have probably posted it on google group
There are no response headers — OPTIONS request is pending and actually never reaches the server
these are the request ones:

Access-Control-Request-Headers:origin, x-requested-with, accept
Access-Control-Request-Method:GET
Cache-Control:no-cache
Origin:http://website.com
Pragma:no-cache

thanks for replying

@petebacondarwin
Copy link
Member

Is this related to #1454 and
#1004?

On 16 November 2012 10:59, grumpyOldRussian notifications@git.luolix.topwrote:

If I didn't think that it might be a bug I would have probably posted it
on google group
There are no response headers — OPTIONS request is pending and actually
never reaches the server
these are the request ones:

Access-Control-Request-Headers:origin, x-requested-with, accept
Access-Control-Request-Method:GET
Cache-Control:no-cache
Origin:http://beta.kontr.tv
Pragma:no-cache

thanks for replying


Reply to this email directly or view it on GitHubhttps://github.com//issues/1585#issuecomment-10443601.

@taralx
Copy link

taralx commented Nov 16, 2012

Almost certainly. Try the workaround in pull #1454.

@pkozlowski-opensource
Copy link
Member

@alexeygolev Could you try to remove the x-requested-with header as described in #1454 and see if this solves the issue?

It is kind of hard to help on this one without more info. Is your app available anywhere on-line? Did you try sniffing HTTP traffic to be sure that a request doesn't leave a browser?

@taralx
Copy link

taralx commented Nov 23, 2012

Was already doing that. For the record, I was opening a local file and having it try to open another local file.

@pkozlowski-opensource
Copy link
Member

@alexeygolev just for the record - what is a browser we are talking about here? Is it, by any chance, IE?

@taralx
Copy link

taralx commented Dec 4, 2012

Oh, sorry. I didn't realize you weren't talking to me. :)

@pkozlowski-opensource
Copy link
Member

@alexeygolev haven't heard from you and it really next to impossible to help more without knowing what is going on in your browser / server. Would love to help more but there are just not enough data. Going to close this one for now, please re-open or post something on the mailing list / IRC when you've got more info.

@ghost
Copy link

ghost commented Oct 24, 2013

@breath103
Copy link

here is a great example for this.

$http.get("http://cdn.api.twitter.com/1/urls/count.json?url=www.google.com&callback=?")
this request turns in to Options request again.

but this works
$.getJSON("http://cdn.api.twitter.com/1/urls/count.json?url=www.google.com&callback=?")

@yarivdev
Copy link

This is still going on.
getJson works fine,
$http.get turns into options request.

@petebacondarwin
Copy link
Member

@yarivdev - normally GET requests are converted to OPTION requests if you are trying to access a resource outside of the current domain. This is part of the CORS spec.

@yarivdev
Copy link

how come it doesn't happen with $.getJson?

Sent from my iPhone

On 20 Oct 2015, at 8:34 PM, Pete Bacon Darwin notifications@github.com wrote:

@yarivdev - normally GET requests are converted to OPTION requests if you are trying to access a resource outside of the current domain. This is part of the CORS spec.


Reply to this email directly or view it on GitHub.

@pkozlowski-opensource
Copy link
Member

how come it doesn't happen with $.getJson?

Probably a different set of HTTP headers is sent.

Once again, OPTIONS requests are sent by a browser, Angular has no control over it. If you compare behaviour of jQuery and AngularJS make sure that you compare all the properties of a request (full URL, request headers, request body etc.).

Impossible to say more based on the info provided. If you still believe that AngularJS does something wrong here, please open a new issue with a clear steps to reproduce (Plunker).

@blaskovicz
Copy link

@yarivdev, see the link that @franklovecchio posted

http://stackoverflow.com/questions/19554414/angularjs-disabling-cors

@alfavat
Copy link

alfavat commented Nov 28, 2018

0
down vote

i do not know if any body still interested in this topic but i am going to tell you my approach i added CORS Options to web config file in my api project and then add [HttpOptions] attribute to my api method and then it started working i do not know if it is the right answer or not but until i find the better solution i am going to user this approach

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants