这是我的网址,
http://api.theahsanzaman.info/token?username=haris123@gmail.com&password=Haris@123&grant_type=password
我希望它像这样编码,
http://api.theahsanzaman.info/token?username%3Dharis123%40gmail.com%26password%3DHaris%40123%26grant_type%3Dpassword
=符号应该由%3D替换 &标志应由%26替换 @符号应替换为%40
我怎样才能改变我的意见?
答案 0 :(得分:0)
如果您想这样做,请删除要从.urlQueryAllowed
字符集中转义百分比的字符,并相应地进行百分比编码:
var allowed = CharacterSet.urlQueryAllowed
allowed.remove(charactersIn: "=@&")
let result = urlString.addingPercentEncoding(withAllowedCharacters: allowed)