IOS URL中含有特殊字符请求失败处理


摘要:一个含有特殊字符的URL,请求失败处理,最好需要NsLog 看请求地址对编码的处理

//    三种处理网址的方法
      NSString *str1 = [@"http://118.212.144.158:8081/?code=123#/work" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSString *str2 = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)@"http://118.212.144.158:8081/?code=123#/work", (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", NULL, kCFStringEncodingUTF8));

    NSString *str3 = [@"http://118.212.144.158:8081/?code=123#/work" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    [self.webV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str2]]];
    
    NSLog(@"str1=======:%@",str1);
    NSLog(@"str2=======:%@",str2);
    NSLog(@"str3=======:%@",str3);
    
    NSLog(@"str1Request=======:%@",[NSURLRequest requestWithURL:[NSURL URLWithString:str1]]);
    NSLog(@"str2Request=======:%@",[NSURLRequest requestWithURL:[NSURL URLWithString:str2]]);
    NSLog(@"str3Request=======:%@",[NSURLRequest requestWithURL:[NSURL URLWithString:str3]]);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM