iOS:WebView加载网址

iOS:WebView加载网址,第1张

概述我试图在UIWebView中打开以下url,但是无法加载,而将其更改为: http://www.google.com 工作正常. 我要加载的url是: [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@%@%@",@"http://m.f 我试图在UIWebVIEw中打开以下url,但是无法加载,而将其更改为:
http://www.Google.com

工作正常.

我要加载的url是:

[webVIEw loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[Nsstring stringWithFormat:@"%@%@%@%@%@",@"http://m.forrent.com/search.PHP?address=",[[bookListing objectForKey:@"Data"] objectForKey:@"zip"],@"&beds=&baths=&price_to=0#{\"lat\":\"0\",\"lon\":\"0\",\"distance\":\"25\",\"seed\":\"1622727896\",\"is_sort_default\":\"1\",\"sort_by\":\"\",\"page\":\"1\",\"startIndex\":\"0\",\"address\":\"",@"\",\"beds\":\"\",\"baths\":\"\",\"price_to\":\"0\"}"]]]];

更新:

我有意逃避双引号,否则给我一个错误.
我通过在浏览器中打开浏览器(笔记本电脑)检查了URL,它的工作原理很好:

浏览器中的网址

http://m.forrent.com/search.PHP?address=92115&beds=&baths=&price_to=0#{%22lat%22:%220%22,%22lon%22:%220%22,%22distance%22:%2225%22,%22seed%22:%221622727896%22,%22is_sort_default%22:%221%22,%22sort_by%22:%22%22,%22page%22:%221%22,%22startIndex%22:%220%22,%22address%22:%2292115%22,%22beds%22:%22%22,%22baths%22:%22%22,%22price_to%22:%220%22}
解决方法 你的代码行很复杂,但基本上这是一个非常简单的代码.

你应该将这个代码从一个内存分解成多个可读的行.
这也将允许您记录并检查您实际创建的URL,如下所示:

NSLog(@“我的url:%@”,urlString);

更新:
我看到你添加了完整的URL. WebvIEw确实无法加载该url(UIWebkit错误101).

导致问题的url的部分是params中的’#’字符和字典.你应该url编码url的那部分.

尝试这个:

Nsstring *address = @"http://m.forrent.com/search.PHP?";Nsstring *params1 = @"address=92115&beds=&baths=&price_to=0";// URL encode the problematic part of the url.Nsstring *params2 = @"#{%22lat%22:%220%22,%22price_to%22:%220%22}";params2 = [self escape:params2];// Build the url and loadRequestNsstring *urlString = [Nsstring stringWithFormat:@"%@%@%@",address,params1,params2];[self.webVIEw loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];

我使用的转义方法:

- (Nsstring *)escape:(Nsstring *)text{    return (__brIDge Nsstring *)CFURLCreateStringByAddingPercentEscapes(NulL,(__brIDge CFStringRef)text,NulL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kcfStringEnCodingUTF8);}
总结

以上是内存溢出为你收集整理的iOS:WebView加载网址全部内容,希望文章能够帮你解决iOS:WebView加载网址所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1112417.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存