UIWebView - 向 url 请求添加额外参数
您好,我有一个网址 http://www.foobar.com
[webView loadRequest:[NSURLRequest requestWithURL:appURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0
]];
现在,当这个网址形成时,我可以设置urlString 具有 webtype=iphone
但对于从那里发出的每个请求,我需要将 webType=iphone 添加到字符串后面。
我认为有某种方法可以使用
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
但还没有通过它得到任何解决方案...任何帮助
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需创建一个返回自定义网址的自定义方法:
然后您就可以:
[webView loadRequest:[NSURLRequest requestWithURL:[self customURLWithPramString:@"name=123&age=123"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]] ;
在本例中传递“name=123&age=123”
just create a custiom method returning the cusom url:
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
为此,可以使用仅实现自定义 loadRequest 的简单包装器子类 UIWebView,也可以子类 NSURLRequest 来更改自定义 URL,如上面 JNK 所说。后面的事情可能更容易做。
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.