Swift在发起get请求时候有时候拼接参数不可避免遇到汉字.
let keyword = "你好"
let encodeWord = keyWord.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlPathAllowed
现在使用encodeWord作为get参数即可
简单介绍一下CharacterSet枚举
/// Returns a character set containing the characters in Unicode General Category Cc and Cf.
public static var controlCharacters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category Zs and `CHARACTER TABULATION (U+0009)`.
public static var whitespaces: CharacterSet { get }
/// Returns a character set containing characters in Unicode General Category Z*, `U+000A ~ U+000D`, and `U+0085`.
public static var whitespacesAndNewlines: CharacterSet { get }
/// Returns a character set containing the characters in the category of Decimal Numbers.
public static var decimalDigits: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category L* & M*.
public static var letters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category Ll.
public static var lowercaseLetters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category Lu and Lt.
public static var uppercaseLetters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category M*.
public static var nonBaseCharacters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Categories L*, M*, and N*.
public static var alphanumerics: CharacterSet { get }
/// Returns a character set containing individual Unicode characters that can also be represented as composed character sequences (such as for letters with accents), by the definition of "standard decomposition" in version 3.2 of the Unicode character encoding standard.
public static var decomposables: CharacterSet { get }
/// Returns a character set containing values in the category of Non-Characters or that have not yet been defined in version 3.2 of the Unicode standard.
public static var illegalCharacters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category P*.
public static var punctuationCharacters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category Lt.
public static var capitalizedLetters: CharacterSet { get }
/// Returns a character set containing the characters in Unicode General Category S*.
public static var symbols: CharacterSet { get }
/// Returns a character set containing the newline characters (`U+000A ~ U+000D`, `U+0085`, `U+2028`, and `U+2029`).
public static var newlines: CharacterSet { get }
/// Returns the character set for characters allowed in a user URL subcomponent.
public static var urlUserAllowed: CharacterSet { get }
/// Returns the character set for characters allowed in a password URL subcomponent.
public static var urlPasswordAllowed: CharacterSet { get }
/// Returns the character set for characters allowed in a host URL subcomponent.
public static var urlHostAllowed: CharacterSet { get }
/// Returns the character set for characters allowed in a path URL component.
public static var urlPathAllowed: CharacterSet { get }
/// Returns the character set for characters allowed in a query URL component.
public static var urlQueryAllowed: CharacterSet { get }
/// Returns the character set for characters allowed in a fragment URL component.
public static var urlFragmentAllowed: CharacterSet { get }