您的位置:首页 > 移动开发

IOS---UIWebview用法点滴

2011-09-26 14:07 323 查看
1. load from url:
从url加载页面


NSURL *url = [NSURL URLWithString:"http://stackoverflow.com"];

NSString *body = @"laadeedaa";

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[request setHTTPMethod: @"POST"];

// Dump the response to the UIWebView

[webView loadRequest:request];

2. 自定义 webview的请求 ,load with customized request

// Do your POST

NSURL *url = [NSURL URLWithString:"http://stackoverflow.com"];

NSString *body = @"laadeedaa";

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod: @"POST"];

[request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];

// Dump the response to the UIWebView

[webView loadRequest:request];

3.查看webveiw的返回

// Dump the response to the UIWebView

[webView loadRequest:request];

NSURLResponse *response = nil;

NSError *error = nil;

NSData *respData = [NSURLConnection sendSynchronousRequest:request

returningResponse:&response

error:&error];

NSString *respString = [[[NSString alloc] initWithData:respData

encoding:NSUTF8StringEncoding] autorelease];

NSString *htmlString = [self doSomethingWith:respString];

[webView loadHTMLString:htmlString baseURL:@"http://stackoverflow.com"];

4.通过js控制webview

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

例如
:  NSString *html = [yourWebView stringByEvaluatingJavaScriptFromString:

@"document.body.innerHTML"];


see also:
http://allseeing-i.com/ASIHTTPRequest/ASIWebPageRequest http://stackoverflow.com/questions/2061393/iphone-sdk-control-websites-in-uiwebview-programmatically http://stackoverflow.com/questions/992348/reading-html-content-from-a-uiwebview http://iphoneincubator.com/blog/tag/uiwebview
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: