I am making a request to the third option on this page: .htm
Im getting back the response I want, but I also get a CORS error which makes no sense to me... They said they have CORS enabled
resultsponent.ts:28 results;state=:1 Failed to load =: No 'Access-Control-Allow-Origin' header is present on the requested resource.
let headers = new Headers();
headers.append('Content-Type', 'text/plain');
let options = new RequestOptions({ headers: headers });
return this.http.get('', options)
.map(this.extractData)
.catch(this.handleError);
The only way I have been able to get around this problem is to download a chrome extension that fixes CORS. But this is a project I need to hand in, so I doubt telling someone to download an extension is going to go over so well...
Yes I have cleared browser cache.
I am making a request to the third option on this page: http://www.groupkt./post/5c85b92f/restful-webservice-to-get-and-search-states-and-territories-of-a-country.htm
Im getting back the response I want, but I also get a CORS error which makes no sense to me... They said they have CORS enabled
results.ponent.ts:28 results;state=:1 Failed to load http://services.groupkt./state/search/USA?text=: No 'Access-Control-Allow-Origin' header is present on the requested resource.
let headers = new Headers();
headers.append('Content-Type', 'text/plain');
let options = new RequestOptions({ headers: headers });
return this.http.get('http://services.groupkt./state/search/USA?text=cal', options)
.map(this.extractData)
.catch(this.handleError);
The only way I have been able to get around this problem is to download a chrome extension that fixes CORS. But this is a project I need to hand in, so I doubt telling someone to download an extension is going to go over so well...
Yes I have cleared browser cache.
Share Improve this question edited Oct 17, 2017 at 21:40 Alberto Martinez 2,6704 gold badges25 silver badges29 bronze badges asked Oct 17, 2017 at 19:49 user5823669user5823669 4- Is part of your project to access that resource (services.groupkt.) from the client side? I ask, because if your project actually involved proxying that resource through your own server, you still have more work to do. Also, you aren't fixing CORS, you're circumventing it. CORS is a security policy to protect users. – zero298 Commented Oct 17, 2017 at 19:51
-
headers.append('Content-Type', 'text/plain');
— This makes no sense. You are making a GET request. There is no content in the request body to describe the content type of. – Quentin Commented Oct 17, 2017 at 19:54 - It all depends on the server. Possible duplicate of stackoverflow./questions/35553500/… – Jimenemex Commented Oct 17, 2017 at 19:56
- I got that text/plain thing from another answer, guess Its pointless lol – user5823669 Commented Oct 17, 2017 at 20:07
1 Answer
Reset to default 11Im getting back the response I want, but I also get a CORS error which makes no sense to me
CORS errors are generated by the client when the server doesn't explicitly grant permission for JavaScript to read the response across origins.
This is entirely independent of whether or not the request generated a good response (i.e. if it was 200 OK or something else).
They said they have CORS enabled
Either:
- They are wrong or
- They have CORS enabled but only under conditions not met by the request you made (e.g. for a different URL)