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

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

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

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

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

/***
stringByAddingPercentEncodingWithAllowedCharacters 对字符串进行编码
  URLFragmentAllowedCharacterSet                                "#%<>[\]^`{|}  
  URLHostAllowedCharacterSet                                    "#%/<>?@\^`{|}  
  URLPasswordAllowedCharacterSet                                "#%/:<>?@[\]^`{|}  
  URLPathAllowedCharacterSet                                    "#%;<>?[\]^`{|}  
  URLQueryAllowedCharacterSet                                   "#%<>[\]^`{|}  
  URLUserAllowedCharacterSet                                    "#%/:<>?@[\]^`
***/
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。