没有获得发布请求响应 - 迅速

时间:2015-04-24 09:55:07

标签: ios iphone web-services swift

我有java网络服务。 Web服务使用HTTPS。我正在使用以下代码处理身份验证质询,但是当我调用POST方法

时,服务器没有响应任何响应
func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge) {


    if challengeUsername.isEqualToString("") || challengePassword.isEqualToString("") {

    }
    else
    {
        if challenge.previousFailureCount == 0{

            println("Received Authentication challenge")

            var nCredentials : NSURLCredential = NSURLCredential(user: challengeUsername, password: challengePassword, persistence: .ForSession)
            var trustRef:SecTrustRef  = challenge.protectionSpace.serverTrust!//challenge.protectionSpace.serverTrust
            var count:CFIndex = SecTrustGetCertificateCount(trustRef)
            if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust
            {
           // challenge.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
                    challenge.sender.useCredential(nCredentials, forAuthenticationChallenge: challenge)
            //challenge.sender.performDefaultHandlingForAuthenticationChallenge!(challenge)
            }
            else
            {
                challenge.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
            }
            println("Responded to authentication challenge")

        }
        else
        {
            println("Previous authentication failed")
        }
    }

}

如果我打电话给GET网络服务,它也会获得正确的响应和数据。不确定为什么会这样,任何形式的帮助都表示赞赏。另外我想知道如何将自签名证书与Web服务请求一起使用?

0 个答案:

没有答案