多次启动NSURLConnection时,我收到这些错误。
但是,并不总是得到这个错误。
Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x9eaa6b0 {NSUnderlyingError=0xae8c730 "bad URL", NSLocalizedDescription=bad URL}
答案 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]];