Search code examples
iosobjective-ciphoneuiwebview

iPhone UIWebView Can't connect Some site


I have used UIWebview to connect accounts.craigslist.org but it doesn't work. If i change the site address to google www.google.com it works. I am using Proxy but I don't think it's proxy problem. code below


self.mWebView.delegate = self;

NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:15.0];
    [self.mWebView loadRequest:urlRequest];

Here is pInfo.list screenshot ( I have seen some solution but doesn't work for me from this site )

And I have applied other solutions with NSURLConnectionDataDelegate delegate

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
    return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    NSArray *trustedHosts = [NSArray arrayWithObjects:@"mytrustedhost",nil];

    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];
}

Error Output screenshot


Solution

  • try this one

    NSString *Url=@"accounts.craigslist.org";
    NSString *str=[NSString stringWithFormat:@"%@",Url];
    NSURL *urls=[[NSURL alloc]initWithString:str];
    
    [_webView loadRequest:[NSURLRequest requestWithURL:urls]];