【发布时间】:2017-07-12 12:59:40
【问题描述】:
我收到以下 POST 请求错误:
发布http://127.0.0.1:port/v1/route2net::ERR_CONNECTION_REFUSED
GET 请求运行良好。 POST失败的可能原因是什么? testPost有错吗?
这是角度服务的一部分:
@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));
}
}
【问题讨论】: