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