我已使用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];
这是(我已经看到了一些解决方案,但对我来说不适用于此网站)
我已经使用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];
}
答案 0 :(得分:0)
尝试这个
NSString *Url=@"accounts.craigslist.org";
NSString *str=[NSString stringWithFormat:@"%@",Url];
NSURL *urls=[[NSURL alloc]initWithString:str];
[_webView loadRequest:[NSURLRequest requestWithURL:urls]];