【问题标题】:HTTPS request on iphone not sent to serveriphone上的HTTPS请求未发送到服务器
【发布时间】:2013-06-16 13:21:51
【问题描述】:

我正在使用 phonegap 为 iphone 开发应用程序。 使用 HTTP 提交 ajax 请求时,一切正常。但是当我切换到 HTTPS 时,请求不会发送到服务器。相同的代码适用于 Android 上的 HTTP 和 HTTPS。

以下是我正在使用的代码,提前感谢您的帮助

var xmlRequest = $.ajax({
    url : "https://test.com",
    type : 'POST',
    contentType : "text; charset=utf-8",
    data : sr,
    dataType : "text",
    headers : { SOAPAction : '"'+soapaction+ '"' },
    success : function( data, textStatus, jqXHR ) {
        console.log("----- xmlRequest.responseText: " + xmlRequest.responseText);
        SOAPClient._onSendSoapRequest(method, async, callback, sch, data);
    },
    error : function( jqXHR, textStatus, errorThrown ) {
        console.log("----- xmlRequest.responseText: " + xmlRequest.responseText);
        console.log("----- errorThrown = " + errorThrown + " textStatus = "+ textStatus );
        ServiceErrorMessage(method, jqXHR.status, errorThrown, xmlRequest.responseText);
    },
    cache: false
});

【问题讨论】:

    标签: iphone ios cordova


    【解决方案1】:

    将此添加到 AppDelegate.m 文件的末尾

    @implementation NSURLRequest(DataController)
    + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
    {
        return YES; 
    }
    @end
    

    【讨论】:

    • 这是否违反了 iOS 准则?这是私有 API 吗?
    猜你喜欢
    • 2018-10-04
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2019-09-23
    相关资源
    最近更新 更多