2

I want to change all user request to use the POST method (as opposed to GET). If the request is already a POST request then append a new parameter 'userId=2382938' to the post data. If the request is GET then change it to POST and add 'userId=2382938'.

I know I can intercept a UIWebView using this. Not sure where to go from here.

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType {

//add post parameter here
}
Tim
  • 957
  • 1
  • 9
  • 8
  • could you be a little more specific as to what you would like to do? – PengOne May 26 '11 at 19:44
  • I want to change all user request to use the POST method (as opposed to GET). If the request is already a POST request then append a new parameter 'userId=2382938' to the post data. If the request is GET then change it to POST and add 'userId=2382938'. Thanks – Tim May 26 '11 at 19:49
  • assuming that u have control over the html inside the webview, you can also do what you want by catching form posts (via onsubmit) inside the html and doing a bit of magic in javascript :) – Ali Kazmi May 26 '11 at 20:10
  • I don't have control over the HTML. It's a 3rd party website. – Tim May 26 '11 at 20:16
  • Look my answer here [Modify URL request](http://stackoverflow.com/a/20484616/1460329) – Jorge Balleza Dec 10 '13 at 02:12

2 Answers2

0

You probably want to do something like that.

(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

   NSMutableURLRequest *modifiedRequest = [request mutableCopy];

   modifiedRequest.URL = [NSURL URLWithString:parametrisedURL]; // here you will add your desired parameters

   modifiedRequest.HTTPMethod = @"POST";

   [webview loadRequest:modifiedRequest];

   // Do other stuff if any

   return YES;
}
Xlander
  • 1,331
  • 12
  • 24
ZaEeM ZaFaR
  • 1,508
  • 17
  • 22
0

From How do I insert a POST request into a UIWebView:

You can use an NSMutableURLRequest, set the HTTP method to POST, and then load it into your UIWebView using -loadRequest.

Community
  • 1
  • 1
PengOne
  • 48,188
  • 17
  • 130
  • 149