2016-03-19 108 views
1

こんにちは私はHttps RequestをSwiftで作成したいと思います。現在、私はIPアドレスでローカルサーバーにアクセスしています。ローカルサーバーは、証明書にアクセスすることによって1つのSSL証明書を持っています。Swift:サーバーSSL証明書を使用してHttpsリクエストを作成する方法

Alamofire.request(.GET, https://ipaddress//, parameters: [param], headers: headers) 
     .responseJSON { response in 
      print(response.request) // original URL request 
      print(response.response) // URL response 
      print(response.data)  // server data 
      print(response.result) // result of response serialization 

      if let JSON = response.result.value { 
       print("JSON: \(JSON)") 


      } 
    } 

は私がこのように与えられてきたが、イムはまだ

のようなエラーを取得要求を行うためとのplist plistの中

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
     <key>192.168.2.223:1021(my local ip)</key> 
     <dict> 
     Include to allow subdomains--> 
      <key>NSIncludesSubdomains</key> 
      <true/> 
      <!--Include to allow insecure HTTP requests--> 
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
      <true/> 
      <!--Include to specify minimum TLS version--> 
      <key>NSTemporaryExceptionMinimumTLSVersion</key> 
      <string>TLSv1.1</string> 
     </dict> 
    </dict> 
</dict> 

に上記のコードを使用している

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) 
+0

IPアドレスをATS plist値で使用することはできません。 –

+0

解決策はありましたか? –

答えて

4

重要:しないでくださいこの製品を使用してください。基本的に、Alamofireでは、アプリケーションの開発とテストの目的で認証をバイパスできます。アプリがApp Storeまたはプロダクションに入る前に削除してください: -

func bypassURLAuthentication() { 
     let manager = Alamofire.Manager.sharedInstance 
     manager.delegate.sessionDidReceiveChallenge = { session, challenge in 
      var disposition: NSURLSessionAuthChallengeDisposition = .PerformDefaultHandling 
      var credential: NSURLCredential? 
      if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { 
       disposition = NSURLSessionAuthChallengeDisposition.UseCredential 
       credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!) 
      } else { 
       if challenge.previousFailureCount > 0 { 
        disposition = .CancelAuthenticationChallenge 
       } else { 
        credential = manager.session.configuration.URLCredentialStorage?.defaultCredentialForProtectionSpace(challenge.protectionSpace) 
        if credential != nil { 
         disposition = .UseCredential 
        } 
       } 
      } 
      return (disposition, credential) 
     } 
    } 

ありがとうございます! これが役立つかどうかお知らせください。 :)

関連する問題