UIWebView - 向 url 请求添加额外参数

发布于 2024-10-06 11:25:13 字数 621 浏览 1 评论 0原文

您好,我有一个网址 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡Ms空城旧梦 2024-10-13 11:25:13

只需创建一个返回自定义网址的自定义方法:

- (NSURL *)customURLWithPramString:(NSString *)pramString{
    return [NSURL URLWithString:[NSString stringWithFormat:@"http://www.foobar.com?%@&webtype=iphone",pramString]];
}

然后您就可以: [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:

- (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

格子衫的從容 2024-10-13 11:25:13

为此,可以使用仅实现自定义 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文