使用POST参数通过UIWebView加载网页 [英] Loading a webpage through UIWebView with POST parameters

查看:98
本文介绍了使用POST参数通过UIWebView加载网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过带有POST参数的UIWebView加载页面?
我可以用参数加载一个嵌入的表单并用javascript填充它们并强制提交,但是有更清洁和更快的方法吗?

Is it possible to load a page through UIWebView with POST parameters? I can probably just load an embedded form with the parameters and fill them in with javascript and force a submit, but is there a cleaner and faster way?

谢谢!

推荐答案

创建POST URLRequest并用它来填充webView

Create POST URLRequest and use it to fill webView

NSURL *url = [NSURL URLWithString: @"http://your_url.com"];
NSString *body = [NSString stringWithFormat: @"arg1=%@&arg2=%@", @"val1",@"val2"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[webView loadRequest: request];

这篇关于使用POST参数通过UIWebView加载网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆