[英]Http Post Request from Angular doesn't work
我以此方式發送發布請求(baseURL是正確的,服務器上存在路徑/ api / backend / valuePairs)。
sendValues(valuepairList:{x:number;fx:number}[]): Observable<boolean> {
const headers = new Headers({'Content-Type': 'application/json'});
const options = new RequestOptions({headers: headers});
console.log("sending to server: ",JSON.stringify(valuepairList)); //this seems ok too
return this.http.post(this.baseUrl + '/api/backend/valuePairs', {'data': JSON.stringify(valuepairList)}, options)
.map(FunctionapproximationService.extractData)
.catch(FunctionapproximationService.handleError);
}
但是在Chrome瀏覽器中以檢查模式/網絡查看網站時,此功能執行過程中未發送任何信息(執行后將顯示功能內部的日志記錄)。 有人知道我在做什么錯嗎? 謝謝。
沒有發送任何消息,因為默認情況下可觀察對象是惰性的。 您需要訂閱它們才能調用HTTP請求。
sendValues(args).subscribe(result => console.log(result))
響應到達時,將調用傳遞給subscribe
函數的函數。 它還接受其他用於錯誤處理的功能,並在流完成時調用該功能,但我將其留給您從文檔中了解。
在RxJS worl中, .subscribe()
基本上就像用parans:( ()
調用普通的JS函數。 要執行功能,您需要調用它。 要執行一個可觀察對象,您需要訂閱它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.