針對這個url編碼問題,我自己理解是只針對get提交的url,因為post的參數不是在url里面。我們提交給服務器的URL必須是有效的才行。
1第一種裝換方式 這個是IOS9出來的新的
NSString *urlStr = @"http://129.168.1.1:31812/login2?username=cyx&pwd=123&type=中文";
NSLog(@"轉換前:%@", urlStr);
// 2.對URL進行轉碼
NSString *escapedPath = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSLog(@"轉換后:%@", escapedPath);
2第二種方式是IOS9以前的
NSString *urlStr = @"http://129.168.1.1:31812/login2?username=cyx&pwd=123&type=中文";
NSLog(@"轉換前:%@", urlStr);
// 2.對URL進行轉碼
urlStr=? [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"轉換后:%@", urlStr);