Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grabbing POST data from UIWebView

Tags:

objective-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

like image 266
bph Avatar asked May 05 '12 00:05

bph


1 Answers

You need to implement the UIWebViewDelegate. There is a hook called "shouldStartLoadWithRequest" that gets called by iOS.

Psueudocode below.

@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
like image 164
Ash Avatar answered Nov 23 '22 11:11

Ash