iOS 4中的角度4 httpd post调用失败

问题描述:

我在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(),但没有运气。

请帮忙吗?

谢谢!

+0

因此呼叫永远不会到达iOS上的服务器? – mast3rd3mon

我们在Nativescript iOS + http连接上发生崩溃和挂起问题,直到昨天。我们切换到https连接我们的服务器的API和一切正在完美现在。

也许它与iOS上的安全/非安全连接有关?

尝试切换到安全连接并查看会发生什么。

如果你不能做到这一点,你可以添加以下到您的info.plist文件,以允许HTTP连接:

<key>NSAppTransportSecurity</key> 
<dict> 
    <!--Include to allow all connections (DANGER)--> 
    <key>NSAllowsArbitraryLoads</key> 
     <true/> 
</dict> 
+1

这就是发生了什么事情,我将协议更改为http并在iOS中工作,现在是时候决定是否切换到https或保留http并包含该规则。谢谢你的时间。 – relez

+0

看来iOS 11不会允许http连接,所以我认为使用https方式是一个安全的选择。 –

+0

还有一件事,我试图在Android中运行https呼叫,并得到了很多错误,其中之一是: System.err:导致:java.security.cert.CertificateException:java.security.cert.CertPathValidatorException:未找到证书路径的信任锚点。 任何想法如何解决它? – relez