如何在alamofire中启用SSL连接

时间:2014-12-19 05:53:52

标签: ssl swift alamofire

如何像AFNetworking一样启用ssl连接:

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

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

https://domain/request

和参数:

email=123@abc.com

已更新

我已经解决了这种情况,因为我将参数编码格式.JSON更改为.URL

1 个答案:

答案 0 :(得分: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