美文网首页
Error Domain=NSURLErrorDomain Co

Error Domain=NSURLErrorDomain Co

作者: 牛程程 | 来源:发表于2018-01-17 22:22 被阅读0次

“Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"”

bug产生的原因:
URL 不能包含 ASCII 字符集。

解决的办法:
把url的字符串进行如下处理。

urlString = [urlString  stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

/***
stringByAddingPercentEncodingWithAllowedCharacters 对字符串进行编码
  URLFragmentAllowedCharacterSet                                "#%<>[\]^`{|}  
  URLHostAllowedCharacterSet                                    "#%/<>?@\^`{|}  
  URLPasswordAllowedCharacterSet                                "#%/:<>?@[\]^`{|}  
  URLPathAllowedCharacterSet                                    "#%;<>?[\]^`{|}  
  URLQueryAllowedCharacterSet                                   "#%<>[\]^`{|}  
  URLUserAllowedCharacterSet                                    "#%/:<>?@[\]^`
***/

相关文章

网友评论

      本文标题:Error Domain=NSURLErrorDomain Co

      本文链接:https://www.haomeiwen.com/subject/qlkpoxtx.html