开发者

UIWebView - Add an extra parameter to the url request

开发者 https://www.devze.com 2023-01-29 02:49 出处:网络
Hi I have a url say http://www.foobar.com [webView loadRequest:[NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号