2017-04-24 85 views
0

我使用Ionic2構建應用程序,並向服務器發送http請求。但是,我得到了一個http請求上的Unexpected end of JSON input。 (其他請求沒有這個問題)Angular2 http get方法返回空_body

我沒有改變任何代碼,但它突然開始給這個錯誤。 (它運行良好,直到上週)

如下所示,如果我在POSTMAN上執行相同的請求,它會返回像圖像中的響應。會有什麼問題?我需要做什麼?

代碼

var url = this.API_URL + 'api/program/information'; 
this.http.get(url).map(res => { 
    res.json(); 
}).subscribe(isloggedin =>{ 
}); 

enter image description here

enter image description here

編輯: 當我刪除從broswer所有Cookie,它工作在第一時間,則不會從第二工作審判。

回答

0

它應該是,

var url = this.API_URL + 'api/program/information'; 
http.get(url).map(response => response.json()) 
.subscribe(isloggedin => this.isloggedin =isloggedin); 
+0

我會在錯誤的'response.json()'部分是因爲響應是空的。正如您在第一張圖片中看到的那樣,_body是空的。 – smchae

+0

你需要傳遞任何標題嗎?你是否改變了API?請求沒有問題 – Sajeetharan

+0

那就是我說的。我沒有改變API。正如我所提到的,服務器上的其他http獲取請求正常工作。 – smchae