摘要:一个含有特殊字符的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]]);