Unable to create request (bad url?) 解决方案
2014-05-13 11:22
309 查看
今天写一个测试demo,遇到如下问题:
功能是为了测试分包下载,大概流程:请求URL,服务器返回一套URLList,自己分别去请求每个url最后把得到得数据进行拼接。
每个url如下:
在得到URLList以后,对每一个url进行请求得时候,就发生了这样得错误,但是把链接复制到浏览器可以正常使用,还有就是如果把链接复制出来,在代码中一字符串名文得方式指定也可以:
上网查了,大多数人是说其中有中文,需要使用:
url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
但是很显眼在以上url中没有中文,结果在网上找了各种方法试都无效,最后解决方法:
Error Domain=ASIHTTPRequestErrorDomain Code=5 "Unable to create request (bad url?)" UserInfo=0x69ba0f0 {NSLocalizedDescription=Unable to create request (bad url?)}
功能是为了测试分包下载,大概流程:请求URL,服务器返回一套URLList,自己分别去请求每个url最后把得到得数据进行拼接。
每个url如下:
http://sandbox.kaka.com/zinx-nj/%2Fbook%2Fb663c2f03f7b36f4f830979e63f2b0%2F20m_by_5m%2Fmain_1.zip?sign=MBOT:DIoOACjY2prt9jy4i84mGUps9qF941:9BRgIQ1btIaa5CZpZ94Mwm42vE%3D&time=1402132737
在得到URLList以后,对每一个url进行请求得时候,就发生了这样得错误,但是把链接复制到浏览器可以正常使用,还有就是如果把链接复制出来,在代码中一字符串名文得方式指定也可以:
NSString *urlString = @"http://sandbox.kaka.com/zinx-nj/%2Fbook%2Fb663c2f03f7b36f4f830979e63f2b0%2F20m_by_5m%2Fmain_1.zip?sign=MBOT:DIoOACjY2prt9jy4i84mGUps9qF941:9BRgIQ1btIaa5CZpZ94Mwm42vE%3D&time=1402132737"; [self rquest:[NSURL URLWithString:urlString]];
上网查了,大多数人是说其中有中文,需要使用:
url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
但是很显眼在以上url中没有中文,结果在网上找了各种方法试都无效,最后解决方法:
NSString *temp = [URLString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSArray *array = [temp componentsSeparatedByString:@"?"]; NSString * encodedString = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge_retained CFStringRef)array[1], NULL, (CFStringRef)@"!*’();:@&=+$,/?%#[]", kCFStringEncodingUTF8); NSString *resultURL = [NSString stringWithFormat:@"%@?%@",array[0],encodedString]; [self request:[NSURL URLWithString:resultURL]];
相关文章推荐
- ASIHTTPRequest Unable to create request (bad url?) Error
- ASIHTTPRequest Unable to create request (bad url?) Error
- ASIHttpRequest出错提示:Unable to create request (bad url?)
- Error Domain=ASIHTTPRequestErrorDomain Code=5 "Unable to create request (bad url?)" UserInfo=0x15f86
- yii2 Bad Request (#400)---Unable to verify your data submission
- tomcat 下部署的应用出现ava.lang.OutOfMemoryError: unable to create new native thread ,解决方案。
- Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
- myeclipse中DB Browse连接mysql出错,UNable to create connection。Check your URL
- yii2框架中表单提交出现Bad Request (#400)---Unable to verify your data submission的错误解决方
- 向svn提交项目报错Can't create session svn: Unable to connect to a repository at URL
- “Unable to create Genymotion virtual devices:Connection timeout”解决方案
- Myeclipse 2016 c1 连接mysql 提示 unable to create connection check your url
- 解决方案:Unable to retrieve the URL endpoint for Service/Port
- Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
- svn: E180001: Unable to open an ra_local session to URL问题解决方案
- 解决方案:Unable to retrieve the URL endpoint for Service/Port
- Myeclipse连接Mysql数据库时提示 unable to create connection .check your url
- error while performing database login with the Dome driver:unable to create connection.check yoururl
- 为subclipse配置http代理,解决“RA layer request failed, Unable to connect to a repository at URL ..." 错误
- 解决方案:Unable to retrieve the URL endpoint for Service/Port