ASIHttpRequest解析带空格的URL时 出错!!!(已解决)

用的是post请求


URL 地址是: ​​http://111.234.51.56/login_member.pl?time=2011.10.01​​(空格)10:10:10..........


URL 不能变了 因为服务器上就这么写的- -!!


报错的信息:2011-09-19 18:16:08.043 AirService[19744:207] Error Domain=ASIHTTPRequestErrorDomain Code=5 "Unable to create request (bad url?)" UserInfo=0x4c54f80 {NSLocalizedDescription=Unable to create request (bad url?)}


解决方案: 编码错误造成的!

解决很简单:

你将URL后面的一部分这样写:


NSString *str = [@"2011.10.01(空格)10:10:10.........." stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://111.234.51.56/login_member.pl?time=%@", str]];

NSLog(@"URL:%@", url);



比如URL中包含汉字、空格等字符时,需要显示的转换一下!!!


反转换这样做: