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