我使用以下代码从webview中的服务器加载网页: -
-(void)loadView
{
[super loadView];
[[self request] setDelegate:nil];
[[self request] cancel];
[self setRequest:[ASIWebPageRequest requestWithURL:navigationURL]];
[[self request] setDelegate:self];
[[self request] setDidFailSelector:@selector(webPageFetchFailed:)];
[[self request] setDidFinishSelector:@selector(webPageFetchSucceeded:)];
[[self request] setShouldPresentProxyAuthenticationDialog:YES];
[[self request] setShouldPresentCredentialsBeforeChallenge:YES];
[[self request] setShouldPresentAuthenticationDialog:YES];
// Tell the request to embed external resources directly in the page
[[self request] setUrlReplacementMode:ASIReplaceExternalResourcesWithData];
// It is strongly recommended you use a download cache with ASIWebPageRequest
// When using a cache, external resources are automatically stored in the cache
// and can be pulled from the cache on subsequent page loads
[[self request] setDownloadCache:[ASIDownloadCache sharedCache]];
// Ask the download cache for a place to store the cached data
// This is the most efficient way for an ASIWebPageRequest to store a web page
[[self request] setDownloadDestinationPath:
[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:[self request]]];
[[self request] startAsynchronous];
}
从用户输入网址的屏幕中选取导航网址。
在此之后
- (void)webPageFetchSucceeded:(ASIHTTPRequest *)theRequest
{ NSString *response = [NSString stringWithContentsOfFile:
[theRequest downloadDestinationPath] encoding:[theRequest responseEncoding] error:nil];
NSString *html = [NSString stringWithContentsOfFile:[theRequest downloadDestinationPath] encoding:NSUTF8StringEncoding error:nil];
NSData* data = [html dataUsingEncoding:NSUTF8StringEncoding];
[web loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:navigationURL];
}
尝试了不同的MIME类型,但没有成功。 链接在iPad的野生动物园中打开非常精细并且显示al d图像但是当我进入webview时它不显示图像的相同链接.. 如何克服这个......无法找到解决方案:(