我在 iOS 中使用 Nativescript 和 Angular 4 进行 POST 调用时遇到了一个奇怪的问题。我已经在 Android 中测试了相同的代码并且运行良好。服务器未注册任何错误,但调用失败。这是我现在使用的代码:
...
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 工作正常。
我已经启用了enableProdMode()
Angular 并且没有运气。
请问有什么帮助吗?
谢谢!