美文网首页
iOS URL编码

iOS URL编码

作者: frankisbaby | 来源:发表于2019-04-17 23:56 被阅读0次

    - (nullableNSString*)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet*)allowedCharactersAPI_AVAILABLE(macos(10.9), ios(7.0), watchos(2.0), tvos(9.0));

    summary:

    Returns a new string made from the receiver by replacing all characters not in the specified set with percent-encoded characters.

    用编码后的百分号字符, 取代所有不在特定集合的字符;

    discussion:

    Entire URL strings cannot be percent-encoded, because each URL component specifies a different set of allowed characters. For example, the query component of a URL allows the “@” character, but that character must be percent-encoded in the password component.UTF-8 encoding is used to determine the correct percent-encoded characters. Any characters in allowedCharacters outside of the 7-bit ASCII range are ignored.

    allowedCharacters代表需要编码的字符,在集合中的话就需要编码。例如结合中包含“|”,编码后就会变成"%7C";

    相关文章

      网友评论

          本文标题:iOS URL编码

          本文链接:https://www.haomeiwen.com/subject/bwkeyqtx.html