NSURLErrorDomain Code = -1000“bad URL”:它的真正含义是什么? [英] NSURLErrorDomain Code=-1000 "bad URL": What does it really mean?

查看:1686
本文介绍了NSURLErrorDomain Code = -1000“bad URL”:它的真正含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个令人困惑的错误。我通过GET方法发送JSON,一个网站将解析并显示数据。问题是我得到错误NSURLErrorDomain代码-1000或更简单地错误的URL。问题是当我检查服务器时,我发送的数据被成功解析并显示。所以我很困惑为什么我会收到这个错误的网址错误。任何人都可以帮助我?



以下是我收到的错误:


Error Domain = NSURLErrorDomain Code = -1000bad URLUserInfo = 0xff73df0 {NSUnderlyingError = 0xff73810bad URL,NSLocalizedDescription = bad URL}

编辑:

  http://sample.com/imwebjson.php?sid=5amp13&job=sendNotes&im_flds = {\ im_uid\: 1,\ im_bookid\: 57,\ im_pagenr\: 1,\ im_notes\:测试%5C %5Cn} 

好吧,你可能会问为什么JSON字符串的某些部分已经被编码了。这些编码部分是特殊字符。我意识到stringByAddingPercentEscapesUsingEncoding是非常不完整的。它不会编码所有特殊字符,更重要的是,当它编码某些特殊字符时,URL根本不会被识别。所以我决定手动编码特殊字符到字符串中。

解决方案

冒号字符(至少可能是其他人,如 {)需要在URL中进行百分比编码。

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?

Here is the error I am receiving:

Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xff73df0 {NSUnderlyingError=0xff73810 "bad URL", NSLocalizedDescription=bad 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.

解决方案

The colon character : (at least, possibly others like " and {) needs to be percent encoded in URLs.

这篇关于NSURLErrorDomain Code = -1000“bad URL”:它的真正含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆