URL Loading System Programming Guide-Encoding URL Data(URL数据编码)
2015-03-09 09:49
387 查看
来源自:URL Loading System Programming Guide
为了编码URL字符串,可以使用Core Foundatin的CFURLCreateStringByAddingPercentEscapes和CFURLCreateStringByReplacingPercentEscapesUsingEncoding函数。
根据 RFC 3986,在 URL 中的保留的字符如下:
因此,为URL正确编码包含在 URL 中UTF 8 字符串,您应该执行以下操作:
如果你想要解码URL片段,首先必须将URL字符串拆分成其组成部分 (字段和路径部分). If you do not decode it,you will be unable to tell the difference (for example) between an encoded ampersand that was originally part of the contents of a field and a bare ampersand that indicated the end of the field. 。
在将URL分成几部分后,可以解码每个部分,如下所示:
参考:
URL 编码:CFURLCreateStringByAddingPercentEscapes
iOS : How to do proper URL encoding?
为了编码URL字符串,可以使用Core Foundatin的CFURLCreateStringByAddingPercentEscapes和CFURLCreateStringByReplacingPercentEscapesUsingEncoding函数。
根据 RFC 3986,在 URL 中的保留的字符如下:
reserved = gen-delims / sub-delims gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
因此,为URL正确编码包含在 URL 中UTF 8 字符串,您应该执行以下操作:
CFStringRef originalString = ... CFStringRef encodedString = CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, originalString, NULL, CFSTR(":/?#[]@!$&'()*+,;="), kCFStringEncodingUTF8);
如果你想要解码URL片段,首先必须将URL字符串拆分成其组成部分 (字段和路径部分). If you do not decode it,you will be unable to tell the difference (for example) between an encoded ampersand that was originally part of the contents of a field and a bare ampersand that indicated the end of the field. 。
在将URL分成几部分后,可以解码每个部分,如下所示:
CFStringRef decodedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding( kCFAllocatorDefault, encodedString, CFSTR(""), kCFStringEncodingUTF8);
参考:
URL 编码:CFURLCreateStringByAddingPercentEscapes
iOS : How to do proper URL encoding?
相关文章推荐
- URL Loading System Programming Guide-Using NSURLConnection
- apple官方文档翻译:URL Loading System Programming Guide
- URL Loading System Programming Guide-使用NSURLSession
- URL Loading System Programing Guide (2)
- iOS URL Loading System
- Table View Programming Guide for iOS---(四)---Navigating a Data Hierarchy with Table Views
- http编程体系结构URL loading system
- (译)Core Data Programming Guide 之 Managed Object Models
- Intel-x86-System-Programming-Guide, Part 1,Chapter 2.6 SYSTEM INSTRUCTION SUMMARY
- Introduction to Core Data Programming Guide
- Intel-x86-System-Programming-Guide, Part 1,Chapter 3.1 MEMORY MANAGEMENT OVERVIEW
- Pre-loading data into the file system cache
- Intel-x86-System-Programming-Guide, Part 1,Chapter 1 ABOUT 4000 THIS MANUAL
- Intel-x86-System-Programming-Guide, Part 1,Chapter 2.2 MODES OF OPERATION
- A Programmer's Guide to Data Mining 2:Get started with recommendation system(User based filtering)
- URL Loading System Programing Guid (1)
- System.Data.SqlClient.SqlException: 必须声明变量 '@ImageUrl'。
- Intel-x86-System-Programming-Guide, Part 1,Chapter 2.3 SYSTEM FLAGS AND FIELDS IN THE EFLAGS REGISTER
- Core Data Model Versioning and Data Migration Programming Guide
- Programming Interview Questions 111: Design url shorten system