相关疑难解决方法(0)

如何使用NSURLConnection连接SSL以获取不受信任的证书?

我有以下简单的代码连接到SSL网页

NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[ NSURLConnection sendSynchronousRequest: urlRequest returningResponse: nil error: &error ];
Run Code Online (Sandbox Code Playgroud)

如果证书是自签名的,那么它会出错.Error Domain=NSURLErrorDomain Code=-1202 UserInfo=0xd29930 "untrusted server certificate".有没有办法将它设置为接受连接(就像在浏览器中你可以按接受)或绕过它的方法?

https objective-c ssl-certificate ios app-transport-security

299
推荐指数
9
解决办法
26万
查看次数

iOS无法执行HTTP GET请求-Error Domain = NSURLErrorDomain Code = -1012

我正在尝试执行HTTP Get请求,但我继续收到Error Domain = NSURLErrorDomain Code = -1012错误.我的代码是:

@try {
    NSString *url = [[NSString alloc] initWithFormat:@"%@%@", @"http://api.mintchat.com/agent/chats/", agentSecret];

    NSLog(@"******Agents Active List URL Str - %@", url);
    NSURL *nsUrl = [NSURL URLWithString:url];  
    NSLog(@"******Agents Active List URL - %@", nsUrl);

   // Make the request, returning a JSON response, just as a plain old string.
   //NSData *jsonDataString = [[NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error: nil] dataUsingEncoding:NSUTF8StringEncoding];

    NSError *error = nil;

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:nsUrl];
    [request setHTTPMethod:@"GET"];
    [request setValue:API_ID forHTTPHeaderField:@"X-API-ID"];
    [request setValue:API_SECRET forHTTPHeaderField:@"X­-API-­SECRET"]; …
Run Code Online (Sandbox Code Playgroud)

get http ios

15
推荐指数
2
解决办法
3万
查看次数

我想忽略证书验证,在哪里以及如何使用XMLRPC Web服务?

我正在访问一个Web服务并在尝试连接时收到此错误(Web服务是XMLRPC,我使用wordpress xmlrpc源代码请求和处理repsonse):

错误域= NSURLErrorDomain代码= -1202"此服务器的证书无效.您可能正在连接到假装为" ** .org" 的服务器,这可能会使您的机密信息面临风险."

WebService的人说要忽略证书验证部分,所以如果有人知道怎么做,那将对我有很大的帮助.

在一些建议之后我使用了下面的NSURLConnection委托,stil同样的错误

 -(BOOL)connection:(NSURLConnection *)connection  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {  
 return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
 }   

 -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {  
 if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])  
if ([trustedHosts containsObject:challenge.protectionSpace.host])  
  [challenge.sender useCredential:[NSURLCredential  credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];  
  [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
Run Code Online (Sandbox Code Playgroud)

iphone xml-rpc simplexmlrpcserver

4
推荐指数
2
解决办法
2万
查看次数