无法创建请求:URL 错误
当我尝试寻找这样的位置:Florida,USA
时一切正常,但是当我像这样尝试:Florida USA
时,我收到了错误:
Unable to create Request (bad url?)
问题属于录制位置上的空格,有什么办法解决这个问题吗?
NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true",theLocationString];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
When i try to look for a location like this: Florida,USA
it goes OK, but when i try it like this: Florida USA
, i got that error:
Unable to create Request (bad url?)
The problem belongs with the spaces on the location taped, is there any way to resolve that?
NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true",theLocationString];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是你需要对字符串进行 urlencode 。空格字符不是有效的网址字符串:
如果
NSASCIIStringEncoding
不起作用,您可以尝试:NSUTF8StringEncoding
..fredrik
I think the problem is that you need to urlencode your string. A space character isn't a valid url string:
If
NSASCIIStringEncoding
doesn't work you could try:NSUTF8StringEncoding
..fredrik