xcode NSURLErrorDomain Code=-1000 "bad URL": 这到底是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10782591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSURLErrorDomain Code=-1000 "bad URL": What does it really mean?
提问by user1412469
I have this confusing error. I am sending JSON through GET method and a website will parse and display the data. The problem is I am getting the error "NSURLErrorDomain Code -1000" or more simply "Bad URL". The thing is when I check the server, the data I sent is successfully parsed and displayed. So I am really confused why am I getting this "bad URL" error at all. Can anyone helped me out?
我有这个令人困惑的错误。我通过 GET 方法发送 JSON,网站将解析并显示数据。问题是我收到错误“NSURLErrorDomain Code -1000”或更简单的“Bad URL”。问题是当我检查服务器时,我发送的数据已成功解析并显示。所以我真的很困惑为什么我会收到这个“错误的 URL”错误。有人可以帮我吗?
Here is the error I am receiving:
这是我收到的错误:
Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xff73df0 {NSUnderlyingError=0xff73810 "bad URL", NSLocalizedDescription=bad URL}
错误域=NSURLErrorDomain 代码=-1000 “错误 URL” UserInfo=0xff73df0 {NSUnderlyingError=0xff73810 “错误 URL”,NSLocalizedDescription=错误 URL}
EDIT:
编辑:
http://sample.com/imwebjson.php?sid=5amp13&job=sendNotes&im_flds={\"im_uid\":"1",\"im_bookid\":"57",\"im_pagenr\":"1",\"im_notes\":"Testing%5C%5Cn"}
Ok you might ask why some parts of the JSON string is encoded already. These encoded parts are special characters. I realized that the stringByAddingPercentEscapesUsingEncoding is very incomplete. It doesn't encode all special characters, and what more is that when it encodes some special characters, the URL is not recognized at all. So I decided to manually encode the special characters into the string.
好的,您可能会问为什么 JSON 字符串的某些部分已经被编码。这些编码部分是特殊字符。我意识到 stringByAddingPercentEscapesUsingEncoding 非常不完整。它不会对所有特殊字符进行编码,更重要的是,当它对某些特殊字符进行编码时,根本无法识别 URL。所以我决定手动将特殊字符编码到字符串中。
采纳答案by JeremyP
The colon character :
(at least, possibly others like "
and {
) needs to be percent encoded in URLs.
冒号字符:
(至少,可能还有其他像"
和{
)需要在 URL 中进行百分比编码。
回答by user2387149
In the GET parameters you have to change spaces " " for "%20"
在 GET 参数中,您必须为“%20”更改空格“”