http - Testing external API's using Angular 2 & Apache -
i trying make http requeset external api using following request:
let headers = new headers({ 'x-requested-with': 'xmlhttprequest', 'content-type': 'application/x-www-form-urlencoded', 'access-control-allow-origin': "*" }); let options = new requestoptions({ headers: headers }); let body = json.stringify({ test: test comments: "test" }); this.http.post("external_api_url", body, options) .map(res => res.json()) .subscribe((data) => { console.log(data); });
when making api call chrome postman plugin, api works without problem.
when i'm trying make call angular 2 app, call not working , returns following error:
xmlhttprequest cannot load my_api_url. response preflight request doesn't pass access control check: no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:4200' therefore not allowed access.
i know can access bypass using no web-security chrome:
chrome.exe --disable-web-security
but wish make work without it...
i tried add header set access-control-allow-origin "*"
in http.conf
described here.
any ideas?
Comments
Post a Comment