HI all, I am trying to use the TextRazor REST API with Ionic 2, but I seem to be only getting EXCEPTION: Response with status: 0 for URL: null
errors in the console. However, the URL provided is definitely not null, and I’ve read up on the CORS header. I’m quite a noob at web dev in general so I’m clueless as to what could be causing this problem.
Here is the code:
let url = 'http://api.textrazor.com/';
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('x-textrazor-key', 'API_KEY');
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Accept-Encoding', 'gzip');
let content = "text=" + encodeURIComponent(text) +
"&extractors=" + encodeURIComponent("dependency-trees,entities");
let options = new RequestOptions({ headers: headers });
return this.http.post(url, content, options).map(res=>res.json());// EXCEPTION HTTP 0
I was wondering if this could be an issue with the API key header value as, despite the fact that the API Key I put in the header was correct, calling http post on other sites that doesn’t need an API key in the header worked fine.
Perhaps Angular 2 / Ionic 2 add whitespace / trailing characters in the header that could be altering the actual values put into headers.append
?
I’d Appreciate any help, thanks in advance.