从 cmd-line 必须明确指定应允许无效/自签名 SSL 证书。我仍然不确定为什么在通过 IDE 运行时不需要这样做,但这是另一个问题。
设置接受无效证书
- 使用核心苹果 API,这可能有点棘手。它似乎是一个私有 API,或者是前面的块。
- AFNetworking 支持此功能。
使用我正在使用的网络堆栈(BBHTTP,顺便说一句,它非常好,而且似乎被低估了),这很简单:
[[BBHTTPRequest postToURL:_serviceUrl data:[envelope data] contentType:@"text/xml"] setup:^(BBHTTPRequest* request)
{
request.allowInvalidSSLCertificates = YES;
} execute:^(BBHTTPResponse* response)
{
if (_logResponses)
{
LogDebug(@"\n\n$$$$$$$$$ Got response: %@", [[NSString alloc] initWithData:[response content] encoding:NSUTF8StringEncoding]);
}
//etc .. . .
} error:^(NSError* error)
{
//etc .. . .
}];