Swift Error Domain = NSURLErrorDomain Code = -1012

时间:2016-07-28 16:52:56

标签: debugging afnetworking nsurlconnection afnetworking-2 afnetworking-3

我是一名新生,在我大一的时候参加夏季项目,经验不足,我收到了错误

  

错误域= NSURLErrorDomain代码= -1012“(null)”   的UserInfo = {NSErrorFailingURLKey = https://localhost/donate/payment.php,   NSErrorFailingURLStringKey = https://localhost/donate/payment.php}

当我尝试通过条带运行信用卡付款时,我的代码是

 func postStripeToken(token: STPToken) {

    let URL = "https://localhost/donate/payment.php"
    let params  : [String: AnyObject] =  ["stripeToken": token.tokenId,
                                          "amount": myInt,
                                          "currency": "usd",
                                          "description": self.emailTextField.text!]

    let manager = AFHTTPRequestOperationManager()
    manager.POST(URL, parameters: params, success: { (operation, responseObject) -> Void in

        if let response = responseObject as? [String: String] {
            UIAlertView(title: response["status"],
                message: response["message"],
                delegate: nil,
                cancelButtonTitle: "OK").show()
        }

    }) { (operation, error) -> Void in
        self.handleError(error!)
    }
}

它想要一个HTTP网址而不是HTTPS,但是当我将其更改为HTTP并且当用户按卡付款时它不安全时会出现错误

  

无法在APP Transport Security上加载资源   策略要求使用安全连接。

无论如何我可以使用HTTPS而不会收到NSURL错误,或者我可以在没有HTTPS的情况下建立安全连接?任何提示都会非常有用!

manager.securityPolicy.allowInvalidCertificates = true;

我也尝试过添加这句话而没有运气。

1 个答案:

答案 0 :(得分:1)

针对此问题“The resource could not be loaded beach the APP Transport Security Policy requires the use of a secure connection”

只需在info.plist

中编写以下代码即可
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>