Reputation: 2339
I am using a http.Request method to make a http call to server. In the browser console I see two http requests. One gives the response as POST,GET,HEAD
with XHR shown as status 200 and the other gives the right response but the XHR status is shown as other. http.Request is in a service and the subscribe is in the component class.
The service class is
export class Httpprovider {
http: Http;
constructor(http: Http){
this.http = http;
}
httpReq(url: string, method: string, data: any, header: Headers){
let headers = new Headers();
headers.append('Content-Type', 'application/json');
console.log(headers);
if (method === 'GET'){ var methods = RequestMethod.Get}
else if (method === 'POST'){ var methods = RequestMethod.Post}
else if (method === 'PUT'){var methods = RequestMethod.Put}
else if (method === 'PATCH'){var methods = RequestMethod.Patch}
else if (method === 'DELETE'){var methods = RequestMethod.Delete}
else {methods = RequestMethod.Get};
return this.http.request(new Request({
method: methods,
url: url,
body: JSON.stringify(data),
headers: headers
})).map(res => res.json());
}
}
Upvotes: 0
Views: 869
Reputation: 657108
Either you are subscribing multiple times to HttpProvider.httpRequ(...).subscribe()
or it's a CORS preflight call (is of type OPTIONS
AFAIR), therefore it's probably the former.
Upvotes: 2