我在iOS中使用Nativescript和Angular 4進行POST調用時出現了一個奇怪的問題。我在Android中測試了相同的代碼,並且工作完美。服務器不會註冊任何錯誤,但呼叫失敗。這是我使用的是現在的代碼:iOS 4中的角度4 httpd post調用失敗
...
import { Http, Headers, Response, RequestOptions } from "@angular/http";
...
let headers = new Headers();
headers.append("Content-Type", "application/x-www-form-urlencoded");
let options = new RequestOptions({ headers: headers });
let body =
"Username=" + this.username
+"&Password=" + this.password;
this.http.post("http://myserver.com/api/login", body, options)
.map(result => result.json())
.subscribe(
result => {
this.loader.hide();
if (result.Authenticated) {
// Do something...
}
else {
Dialogs.alert({title: 'Error', message: "Username and/or password are incorrect.", okButtonText: "Close"});
}
},
error => {
Dialogs.alert({title: 'Error', message: "There was an error trying to send the request, please try again later.", okButtonText: "Close"});
}
)
這個應用程序顯示我There was an error trying to send the request, please try again later.
消息,但沒有錯誤的服務器和奇怪的是,Android的正常工作。
我已經在Angular中啓用了enableProdMode()
,但沒有運氣。
請幫忙嗎?
謝謝!
因此呼叫永遠不會到達iOS上的服務器? – mast3rd3mon