IOS---UIWebview用法点滴
2011-09-26 14:07
323 查看
1. load from 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
例如
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
从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
相关文章推荐
- iOS中UIWebView的介绍及用法
- ios中UIWebview和asiHttprequest的用法
- iOS-69-WKWebview用法与UIWebview对比(附demo、PPT)
- iOS开发之UIWebView的常见一些用法
- iOS开发之UIWebView的常见一些用法
- iOS开发>学无止境 - UIWebView用法详解及代码分享
- IOS关于UIWebView简单用法
- iOS UIWebView的基本用法
- IOS开发 - UIWebView(用法全面介绍,含最全的JS交互)
- iOS UIWebView stringByEvaluatingJavaScriptFromString的用法
- iOS_UIWebView用法mark
- IOS 学习 UIWebView的用法
- iOS-UIWebView的用法,js交互
- iOS中 UIWebView 基本用法
- iOS UIWebView 全屏播放视频横屏 app其他页面不支持横屏
- iOS block的用法
- IOS 中 hidesBottomBarWhenPushed的用法
- iOS 代码规范~get方法、const用法
- IOS_禁用UIWebView的ActionSheet
- iOS开发——获取UIWebView中视频的长度与播放进度等信息