我發現[NSURL URLWithString:]方法會自動跳過傳遞給它的url字符串中的一些字符。例如它脫離了括號。但是,URL字符串中包含的其他非法律網址字符<和>導致無爲什麼[NSURL URLWithString:]會轉義url字符串中的某些字符,而不會轉換爲其他字符?
[[NSURL URLWithString:@"http://foo.bar/?key[]=value[]"] absoluteString]
返回相同結果的方法返回與
[@"http://foo.bar/?key[]=value[]" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
同時,
[NSURL URLWithString:@"http://foo.bar/?key[]=value[]<>"] returns nil, not a url with an escaped string.
究竟是什麼在啓動NSURL實例時發生?爲什麼它逃脫(也許)只有括號?
你仍在零* myUrl = [NSURL URLWithString:[@「http://foo.bar/?key [] = value [] <>」stringByAddingPercentExcapesUsingEncoding:NSUTF8Encoding]];'? – Sam