解决ios开发中不合法的网络请求地址

  

  NSString *const kWebsite = @"http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fr=&sf=1&fmq=1459502303089_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=风景";ui

这是一个百度图片风景分类里的图片地址,当我发送请求时发生Unsuppotedurl错误url

百度了一下,产生错误的缘由是URL 不能包含 ASCII 字符集,汉字, 这样的字符必须进行转义的字符blog

    NSString *urlString = [kWebsite stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];图片

相关文章
相关标签/搜索