OPTIONS issue #99

Closed
solisoft opened this Issue Jan 11, 2016 · 19 comments

Comments

Projects
None yet
3 participants
@solisoft
qwest.get(my_IP')
     .then(function(xhr, response) {
        alert(response);
     });

Raise an error Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

How can I add "Access-Control-Allow-Origin: *" in headers ?

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

You have an headers option available (see the docs). But I think you're doing a CORS request, then you must have the according headers set on the response from your server : http://www.html5rocks.com/en/tutorials/cors/

Owner

pyrsmk commented Jan 11, 2016

You have an headers option available (see the docs). But I think you're doing a CORS request, then you must have the according headers set on the response from your server : http://www.html5rocks.com/en/tutorials/cors/

@pyrsmk pyrsmk closed this Jan 11, 2016

@solisoft

This comment has been minimized.

Show comment
Hide comment
@solisoft

solisoft Jan 11, 2016

Well the same request using jQuery $.get method works fine !?

Well the same request using jQuery $.get method works fine !?

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

They probably have some additional code. Did you test the headers option or anything else from the article?

Owner

pyrsmk commented Jan 11, 2016

They probably have some additional code. Did you test the headers option or anything else from the article?

@solisoft

This comment has been minimized.

Show comment
Hide comment
@solisoft

solisoft Jan 11, 2016

Yes they have Access-Control-Allow-Origin: * in the request header ... I wasn't able to add it with qwest

Yes they have Access-Control-Allow-Origin: * in the request header ... I wasn't able to add it with qwest

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

The Access-Control-Allow-Origin: * needs to come from the server, not from qwest. As the returned error is saying, especially in the last sentence : No 'Access-Control-Allow-Origin' header is present on the requested resource.

That's why I've posted this article about CORS : http://www.html5rocks.com/en/tutorials/cors/

Because it seems you're not understanding well what is happening ^^

Owner

pyrsmk commented Jan 11, 2016

The Access-Control-Allow-Origin: * needs to come from the server, not from qwest. As the returned error is saying, especially in the last sentence : No 'Access-Control-Allow-Origin' header is present on the requested resource.

That's why I've posted this article about CORS : http://www.html5rocks.com/en/tutorials/cors/

Because it seems you're not understanding well what is happening ^^

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

Is the example you've posted above is the complete code for the request? You have no data or other options set on qwest?

Owner

pyrsmk commented Jan 11, 2016

Is the example you've posted above is the complete code for the request? You have no data or other options set on qwest?

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

To well understand what's happening on the request, read this specific section : http://www.html5rocks.com/en/tutorials/cors/#toc-adding-cors-support-to-the-server

Furthermore, CORS is activated by your request because it seems you're running the request on a different domain than the resource itself.

Owner

pyrsmk commented Jan 11, 2016

To well understand what's happening on the request, read this specific section : http://www.html5rocks.com/en/tutorials/cors/#toc-adding-cors-support-to-the-server

Furthermore, CORS is activated by your request because it seems you're running the request on a different domain than the resource itself.

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

With PHP a simple header('Access-Control-Allow-Origin: *'); do the trick ;)

Owner

pyrsmk commented Jan 11, 2016

With PHP a simple header('Access-Control-Allow-Origin: *'); do the trick ;)

@solisoft

This comment has been minimized.

Show comment
Hide comment
@solisoft

solisoft Jan 11, 2016

On my ruby script I use :

before do
    response['Access-Control-Allow-Origin'] = "*" # Allow any origin
 end

Without that, jQuery raise an error too !

But here the response after a simple $.get

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 136
Connection: keep-alive
Status: 200 OK
Access-Control-Allow-Origin: *
Date: Mon, 11 Jan 2016 16:19:22 GMT
X-Powered-By: Phusion Passenger 5.0.23
Server: nginx/1.8.0 + Phusion Passenger 5.0.23

As you can see, Access-Control-Allow-Origin: * is there.

I will copy /paste both jquery and Qwest headers and both answers

And yes I use XDomain :)

On my ruby script I use :

before do
    response['Access-Control-Allow-Origin'] = "*" # Allow any origin
 end

Without that, jQuery raise an error too !

But here the response after a simple $.get

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 136
Connection: keep-alive
Status: 200 OK
Access-Control-Allow-Origin: *
Date: Mon, 11 Jan 2016 16:19:22 GMT
X-Powered-By: Phusion Passenger 5.0.23
Server: nginx/1.8.0 + Phusion Passenger 5.0.23

As you can see, Access-Control-Allow-Origin: * is there.

I will copy /paste both jquery and Qwest headers and both answers

And yes I use XDomain :)

@solisoft

This comment has been minimized.

Show comment
Hide comment
@solisoft

solisoft Jan 11, 2016

I Just found my issue ... Qwest send an OPTIONS ...then my webservice raise a 404 error
It is normal ?

jQuery (OK)

$.get("http://myip/vehicles/search")

Request

GET /vehicles/search HTTP/1.1
Host: 167.114.253.203
Connection: keep-alive
Accept: /
Origin: http://localhost:8081
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Referer: http://localhost:8081/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Response

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 28
Connection: keep-alive
Status: 200 OK
Access-Control-Allow-Origin: *
Date: Mon, 11 Jan 2016 16:36:12 GMT
X-Powered-By: Phusion Passenger 5.0.23
Server: nginx/1.8.0 + Phusion Passenger 5.0.23

Qwest (NOK)

qwest.get("http://myip/vehicles/search")

Request

OPTIONS /vehicles/search HTTP/1.1
Host: 167.114.253.203
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: http://localhost:8081
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Access-Control-Request-Headers: accept, cache-control
Accept: /
Referer: http://localhost:8081/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Response

HTTP/1.1 404 Not Found
Content-Length: 9
Connection: keep-alive
Status: 404 Not Found
X-Cascade: pass
Date: Mon, 11 Jan 2016 16:36:08 GMT
X-Powered-By: Phusion Passenger 5.0.23
Server: nginx/1.8.0 + Phusion Passenger 5.0.23

I Just found my issue ... Qwest send an OPTIONS ...then my webservice raise a 404 error
It is normal ?

jQuery (OK)

$.get("http://myip/vehicles/search")

Request

GET /vehicles/search HTTP/1.1
Host: 167.114.253.203
Connection: keep-alive
Accept: /
Origin: http://localhost:8081
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Referer: http://localhost:8081/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Response

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 28
Connection: keep-alive
Status: 200 OK
Access-Control-Allow-Origin: *
Date: Mon, 11 Jan 2016 16:36:12 GMT
X-Powered-By: Phusion Passenger 5.0.23
Server: nginx/1.8.0 + Phusion Passenger 5.0.23

Qwest (NOK)

qwest.get("http://myip/vehicles/search")

Request

OPTIONS /vehicles/search HTTP/1.1
Host: 167.114.253.203
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: http://localhost:8081
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Access-Control-Request-Headers: accept, cache-control
Accept: /
Referer: http://localhost:8081/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Response

HTTP/1.1 404 Not Found
Content-Length: 9
Connection: keep-alive
Status: 404 Not Found
X-Cascade: pass
Date: Mon, 11 Jan 2016 16:36:08 GMT
X-Powered-By: Phusion Passenger 5.0.23
Server: nginx/1.8.0 + Phusion Passenger 5.0.23

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

Yes it's normal. The explanations from a previous issue : #90
Maybe it could fix your problem.

Owner

pyrsmk commented Jan 11, 2016

Yes it's normal. The explanations from a previous issue : #90
Maybe it could fix your problem.

@solisoft

This comment has been minimized.

Show comment
Hide comment
@solisoft

solisoft Jan 11, 2016

Yep, adding { cache:true } works for me too ! Thank you for your help !

Yep, adding { cache:true } works for me too ! Thank you for your help !

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

Great!

This OPTIONS issue is really annoying by the way...

Owner

pyrsmk commented Jan 11, 2016

Great!

This OPTIONS issue is really annoying by the way...

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

I'm reopening this issue to have a reminder. I need to modify how the qwest's cache is working.

Owner

pyrsmk commented Jan 11, 2016

I'm reopening this issue to have a reminder. I need to modify how the qwest's cache is working.

@pyrsmk pyrsmk reopened this Jan 11, 2016

@solisoft

This comment has been minimized.

Show comment
Hide comment
@solisoft

solisoft Jan 11, 2016

nice, good luck :)

nice, good luck :)

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

Thanks ;)

Owner

pyrsmk commented Jan 11, 2016

Thanks ;)

@solisoft solisoft changed the title from Access-Control-Allow-Origin is missing in headers to OPTIONS issue Jan 11, 2016

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 11, 2016

Owner

Related to this PR : #73

Owner

pyrsmk commented Jan 11, 2016

Related to this PR : #73

@pyrsmk

This comment has been minimized.

Show comment
Hide comment
@pyrsmk

pyrsmk Jan 12, 2016

Owner

I'll just update the doc since Cache-Control seems the best way to handle request caching.

Owner

pyrsmk commented Jan 12, 2016

I'll just update the doc since Cache-Control seems the best way to handle request caching.

@pyrsmk pyrsmk closed this Jan 12, 2016

@cdll

This comment has been minimized.

Show comment
Hide comment
@cdll

cdll Sep 19, 2016

oh thanks all above, i ve got this problem too and finally i found that i had wrongly spelling header as headers, wish anyone seeing this to check it out~ : )

cdll commented Sep 19, 2016

oh thanks all above, i ve got this problem too and finally i found that i had wrongly spelling header as headers, wish anyone seeing this to check it out~ : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment