UIWebView - Add an extra parameter to the url request
Hi I have a url say http://www.foobar.com
[webView loadRequest:[NSURLRequest requestWithURL:appURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0
]];
Now when this url is formed i can set the urlString to have开发者_JAVA技巧 webtype=iphone
But for every single request that comes from there onwards I need to add webType=iphone to back of the string.
I figured there is some way using
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
But didnt get any solution through it yet... any help
just create a custiom method returning the cusom url:
- (NSURL *)customURLWithPramString:(NSString *)pramString{
return [NSURL URLWithString:[NSString stringWithFormat:@"http://www.foobar.com?%@&webtype=iphone",pramString]];
}
Then you can just go: [webView loadRequest:[NSURLRequest requestWithURL:[self customURLWithPramString:@"name=123&age=123"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]];
where you pass "name=123&age=123" in this case
To do this, either subclass UIWebView with a simple wrapper that only implements a custom loadRequest or subclass NSURLRequest to change the customURL as JNK said above. It's probably easier to do the later tho.
精彩评论