I am getting the following error with POST request:
POST http://127.0.0.1:port/v1/route2 net::ERR_CONNECTION_REFUSED
GET request is working perfectly fine. What could be the possible reason for the failure of POST? Is there any mistake in the testPost?
Here is the part of angular service:
@Injectable()
export class SampleService {
private _getUrl: string = 'http://<server-ip>/v1/route1';
private _postUrl: string = 'http://127.0.0.1:<port>/v1/route2';
constructor(private _http: Http) {}
testGet() {
return this._http.get(this._getUrl).map((response: Response) => response.json());
}
testPost() {
const headers = new Headers();
headers.append('Content-Type', 'application/json; charset=utf-8');
this._http.post(this._postUrl, JSON.stringify({'key1': 'value1', 'key2': 'value2'}), headers).subscribe(() => {}, err => console.error(err));
}
}