1
我想發送一個http post請求到後端rest api。這裏是http服務的代碼:Http post請求不起作用
@Injectable()
export class requestService{
constructor(private _http:Http){}
postRequest(request:any){
console.log("Here is post")
const body=JSON.stringify(request);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this._http.post('http://localhost:8080/requests',body,options).map(res=> console.log(res.headers));
}
}
我相信我的後端工作正常。我成功發送郵遞員的郵寄請求。但是,當我使用我的服務發送請求時,沒有任何反應。沒有錯誤。而且,該對象也不會記錄到後端。
那麼,這是什麼問題?
試試這個----'this._http.post ('http:// localhost:8080/requests',body,options).map(res => console.log(res.data));' – micronyks
我不知道角度,但你確定y你甚至會發現錯誤?你是否有錯誤的回調? –
@micronyks它不起作用。 –