Reputation: 35
I'm testing this web service with resttesttest and getting the same error all the time:
Oh no! Javascript returned an HTTP 0 error. One common reason this might happen is that you requested a cross-domain resource from a server that did not include the appropriate CORS headers in the response. Better open up your Firebug...
Is this something with the URL or it's just my ignorance?
How to get JSON data from there?
Update. Solution found.
There was 2 reasons why my request didn't work:
1) I've copied the url from a pdf file and because of that it had some problems with encoding, which resulted in requesting the url in Punycode.
2) For some reason resttesttest didn't want to work even with correct url so I've checked once again in Chrome's Advanced REST client and that worked for me.
Upvotes: 1
Views: 4419
Reputation: 76
You need to set what headers to allow, in order to get a Cross-origin resource sharing (wiki here). If you use Node.JS, check something like this:
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'Origin, Accept, Accept- Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Response-Time, X-PINGOTHER, X-CSRF-Token,Authorization');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
Or use your language syntax to set response headers.
Upvotes: 1