我一直在使用以下代码
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
operation.allowsInvalidSSLCertificate=YES;
Run Code Online (Sandbox Code Playgroud)
现在我已将AFNetworking更改为2.0的最新版本.operation.allowsInvalidSSLCertificate不与工作了AFHTTPRequestOperation.根据我使用的文件
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES;
Run Code Online (Sandbox Code Playgroud)
我的请求代码是
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog (@"success: %@", operation.responseString);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", error.description);
}
];
[operation start];
[operation waitUntilFinished];
Run Code Online (Sandbox Code Playgroud)
但这不适用于需要证书的HTTPS.我应该怎么做才能使这项工作?
默认情况下,example.com
解析为123.123.123.123
,
但如果我希望它得到解决100.100.100.100
.
对于http,我只需将URL更改http://100.100.100.100
为标题为"Host:example.com".
但它不适用于HTTPS.(错误:SSL证书问题:证书链无效).
我的问题不是原因,我不想跳过证书验证.
如何在Objective-C中获得与curl相同的效果
--resolve
选项:
--resolve <host:port:address>
Provide a custom address for a specific host and port pair. Using this, you can make the curl requests(s)
use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort
of /etc/hosts alternative provided on the command line. The port number should be the number used for the
specific protocol the host will …
Run Code Online (Sandbox Code Playgroud)