错误域= NSURLErrorDomain代码= -1000“错误的URL”UserInfo = 0x9eaa6b0

时间:2013-08-17 10:28:03

标签: ios6 nsurlconnection xcode4.6

多次启动NSURLConnection时,我收到这些错误。

但是,并不总是得到这个错误。

Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x9eaa6b0 {NSUnderlyingError=0xae8c730 "bad URL", NSLocalizedDescription=bad URL}

1 个答案:

答案 0 :(得分:2)

网址中有空格是造成错误的原因。

NSString *urlString =[NSString stringWithFormat:@"&street=%@&street2=&city=%@&state=%@&
zipcode=%@&candidates=10", address.address2,address.city, address.state, address.zip5];
NSLog(@"BAD URL - %@",urlString ); // there is space in url

NSString *encodedUrl = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSLog(@" CORRECT URL - %@", encodedUrl); // url encode that space by %20


NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL RLWithString:encodedUrl]];