我在服务器上发出请求,在 URL 中有空格
http://xxxxxxxx.com/api/api.php?func=showAllwedsdwewsdsd¶ms[]=Saudi%20Arab¶ms[]=all
我收到错误错误 URL 所以,
我用了
downloadURL = [downloadURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
但由于这个原因,我得到了奇怪的 URL
http://sdsdsdsdsdsd.com/api/api.php?func=showAllsdsd¶ms5262721536=Saudi 0X0P+0rabia¶ms5 8288=All
我也在使用
downloadURL= [downloadURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
但又像奇怪的网址
http://xxxxxxxxx.com/api/api.php?func=showsdsdsd¶ms[]=Saudi 0X1.240DC0D824P-807rabia¶ms[]=All
请帮助我如何解决这个问题
编辑粘贴大部分代码
PropertyXMLDownloader *download=[[PropertyXMLDownloader alloc]init];
[download setDelegate:self];
firstAppDelegate *del=(firstAppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"Country is %@",del.country);
NSLog(@"State is %@",del.state);
// del.country=[del.country stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *downloadURL=[NSString stringWithFormat:@"http://xxxxxxxx.com/api/api.php?func=showAll¶ms[]=Saudi Arabia¶ms[]=%@",@"all"];
// downloadURL= [downloadURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
//downloadURL = [downloadURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@" "];
downloadURL = [[downloadURL componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString:@"%20"];
NSLog(downloadURL);
[download startDownloading:downloadURL];