2
我想用GET參數發送URL:NSURL不轉換安全的字符串
let customAllowedSet = NSCharacterSet(charactersInString:"=\"#%/<>[email protected]\\^`{|}&").invertedSet
guard let safeUrl = "\(GVariables.Url)?id=\(self.UUID)&device_name=\(UIDevice.currentDevice().name)&email=\(email)&first_name=\(firstName)&last_name=\(lastName)".stringByAddingPercentEncodingWithAllowedCharacters(customAllowedSet) else {
return
}
print(safeUrl)
guard let url = NSURL(string: safeUrl) else {
return
}
print(url)
輸出是:
的http:%2F%2Fmyurl.com:8000%2FS%2F%3Fid% 3D15FDA6B3-C51A-4057-8F98-0143981CC5C8%26device_name%3DArtem的 iPhone%26email%3D%26first_name%3D%26last_name%3D
但轉換爲NSURL總是返回nil
。
這可能意味着你'customAllowedSet'故障。它是如何實現的? – Moritz
對不起,新增'''customAllowedSet''' – Arti
哦,謝謝。有用 – Arti