从UIWebView抓取POST数据 [英] Grabbing POST data from UIWebView
本文介绍了从UIWebView抓取POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能在UIWebView中按下提交按钮时捕获POST数据并将其保存.我应该使用javascript并添加eventlisteners以便在提交之前获得值吗?如果是这样,我如何才能将数据返回到obj c中的代码?否则,有没有更简单的方法?谢谢
I was wondering if it were possible to grab POST data and save it when a submit button was pressed in a UIWebView. Should I be using javascript and adding eventlisteners so that I can get the values before the submit goes through? If so, how would I be able to get the data back to my code in obj c? Otherwise, is there any easier way? Thanks
推荐答案
您需要实现UIWebViewDelegate.有一个叫做"shouldStartLoadWithRequest"的钩子,iOS会调用它.
You need to implement the UIWebViewDelegate. There is a hook called "shouldStartLoadWithRequest" that gets called by iOS.
下面的伪代码.
@interface MyController<UIWebViewDelegate>
@end
@implementation MyController
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// do your magic
NSData *data = request.HTTPBody; // contains the HTTP body as in an HTTP POST request.
// return YES to continue to load the URL
}
@end
这篇关于从UIWebView抓取POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文