iPhone UIWebView无法连接某些网站

时间:2016-09-10 03:37:57

标签: ios objective-c iphone uiwebview

我已使用UIWebview进行连接 accounts.craigslist.org 但它不起作用。 如果我将网站地址更改为Google www.google.com 有用。 我正在使用代理,但我不认为这是代理问题。 代码

self.mWebView.delegate = self;

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

这是pInfo.list screenshot(我已经看到了一些解决方案,但对我来说不适用于此网站)

我已经使用NSURLConnectionDataDelegate委托

应用了其他解决方案
- (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

1 个答案:

答案 0 :(得分:0)

尝试这个

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

[_webView loadRequest:[NSURLRequest requestWithURL:urls]];