POST data collection from UIWebView

I was interested to know if I was able to get the POST data and save it when the submit button in UIWebView is clicked. Should I use javascript and add eventlisteners so that I can get the values ​​before sending? If so, how can I get the data back to my code in obj c? Otherwise, is there an easier way? Thanks

+6
source share
1 answer

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

Pseudocode 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 
+11
source

Source: https://habr.com/ru/post/914940/


All Articles