CORS rule doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2017 07:58 AM
Dear friends,
I've been trying all morning to get this working, but sadly I failed and I must ask for your help.
This is what I did:
- create a javascript POST code using the Rest Api Explorer. It worked, so I copied it in my website (changing the proxy password of the generated code with the real one ofc)
- create a CORS rule: REST -> CORS RULE
- Name: Amazon
- Domain: http://*.amazonaws.com
- Rest API: Table API
- Http Method: POST
- Http Headers: Access-Control-Allow-Origin: http://*.amazonaws.com
The Http Headers in particular I tried so many different combinations, but the result is always the same. On my js console I see an OPTIONS call being made (HTTP 200), with request:
- Accept:*/*
- Accept-Encoding:gzip, deflate, sdch, br
- Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
- Access-Control-Request-Headers:authorization, content-type
- Access-Control-Request-Method:POST
- Cache-Control:no-cache
- Connection:keep-alive
- Host:dev27487.service-now.com
- Origin:http://xxxxxxx.compute.amazonaws.com:8080
- Pragma:no-cache
- Referer:http://xxxxxx.compute.amazonaws.com:8080/querier
- User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
And response:
- Content-Encoding:gzip
- Date:Mon, 13 Mar 2017 14:40:58 GMT
- Server:ServiceNow
- Set-Cookie:JSESSIONID=399D84D8357AE2C243C2C87037712647;Secure; Path=/; HttpOnly
- Set-Cookie:BIGipServerpool_dev27487=830505994.54334.0000; path=/
- Strict-Transport-Security:max-age=15768000; includeSubDomains;
- Transfer-Encoding:chunked
- Vary:Origin
- My understanding is that the response should have included the headers like Access-Control-Request-Headers, but it doesn't no matter what I do on the SN instance.
- What am I missing?
- I'm pretty much out of ideas or tries here 😞
- Thank you so much,
- Roberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2017 09:52 PM
Here's what I get when doing a GET request against my demo instance from localhost.
Request Headers like this for the Options call:
- Request URL:https://...service-now.com/api/now/stats/incident?sysparm_query=active%3Dtrue&sysparm_count=true&sys...
- Request Method:OPTIONS
- Status Code:200 OK
- Remote Address:149.96.32.10:443
- Referrer Policy:no-referrer-when-downgrade
- And Response Headers like this:
- Access-Control-Allow-Credentials:true
- Access-Control-Allow-Headers:authorization,content-type
- Access-Control-Allow-Methods:GET,POST
- Access-Control-Allow-Origin:http://0.0.0.0:8000
- Access-Control-Max-Age:0
Followed by this for the actual GET request:
- Request URL:https://...service-now.com/api/now/stats/incident?sysparm_query=active%3Dtrue&sysparm_count=true&sys...
- Request Method:GET
- Status Code:200 OK
- Remote Address:149.96.32.10:443
- Referrer Policy:no-referrer-when-downgrade
- Response Headers
- Access-Control-Allow-Credentials:true
- Access-Control-Allow-Origin:http://0.0.0.0:8000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2017 02:25 AM
Hi Matthew,
Can you please share what you have put in your cors rule entry. I am trying to do a GET call on incident table and hitting similar issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 01:16 PM
I have a similar error. The CORS rule will allow you to customize the request header for an external service, but the response header must be set by the server that you are interacting with. Your AWS service needs to set the headers that you are looking for on the response, which is why you are not seeing Access-Control-Request-Headers. You can see a bit more here.
In terms of using the CORS rule, you need to set a comma-delimited list of headers, and they will be added to Access-Controler-Allow-Headers automatically. e.g.
Domain: *.domain.com
Http Headers: x-usertoken,content-type
will include "x-usertoken" and on the request headers to the specified domain (documentation). No need for trying to specify the domain in the headers list itself.