2014-12-19 88 views
1

如何启用SSL连接如何启用SSL连接就像AFNetworking那样:在alamofire

self.manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:kHostName]]; 
self.manager.securityPolicy.allowInvalidCertificates = YES; 

我在我的情况下,既没有用户名,也没有密码,只需post request这样

https://domain/request 

和参数:

[email protected] 

修订

我已经解决了这个问题,因为我将参数编码形式.JSON更改为.URL

+0

你可以分享如何使AuthenticationChallenge为credentialUser和密码alamofire – Max 2015-09-04 12:46:30

+0

@Max对我来说,工作代码,没有任何用户名或密码,我想你可以通过马吕斯检查答案下方,或检查Alamofire文件。祝你好运! :) – HamGuy 2015-09-06 01:53:49

回答

2

什么:

let user = "user" 
let password = "password" 

Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(user)/\(password)") 
     .authenticate(user: user, password: password) 
     .response {(request, response, _, error) in 
      println(response) 
     } 

https://github.com/Alamofire/Alamofire

无效的HTTPS证书功能似乎还没有可用 - https://github.com/Alamofire/Alamofire/issues/116

+1

我没有用户名和密码在我的情况下,所以提示来自文件没有帮助,我现在已经解决了,因为我更改参数编码从.JSON到.URL Alamofire运作良好。 – HamGuy 2014-12-24 02:07:53