2016-03-19 17 views
1

Merhaba Https Request uygulamasını Swift'de yapmak istiyorum. Şu anda ip adresi üzerinden yerel sunucuya erişiyorum. Yerel Sunucu, sertifikaya erişerek şu anda böyle bir şekilde yapmak istemiyorum.Swift: Sunucu SSL Sertifikası Kullanarak Https Talebi Nasıl Yapılır?

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)") 


      } 
    } 

Ben böyle verdik ama im hala

gibi hata alıyorum istekte için ve 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> 

yukarıdaki kod kullanmış

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

IP adreslerini ATS plist değerlerinde kullanamazsınız. –

+0

Çözüm aldınız mı? –

cevap

4

ÖNEMLİ: YAPMAYIN BU ÜRETİMDE KULLANIN. Temel olarak, Alamofire ile uygulama geliştirme ve test amaçlı kimlik doğrulamasını atlayabilirsiniz. Uygulama App Store'da veya üretimde bulunmadan önce kaldırdığınızdan emin olun: -

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) 
     } 
    } 

Teşekkür ederiz! Bu yardımcı olursa bana bildirin. :)

İlgili konular