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
}
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.
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;
}
精彩评论