欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS-AFNetworking源码解析(五)

程序员文章站 2022-06-15 23:30:17
AFURLRequestSerializationAFURLRequestSerialization是用来对发出的请求进行一些处理AFPercentEscapedStringFromString方法将string里面的:#[]@!$&’()*+,;=字符替换成%NSString * AFPercentEscapedStringFromString(NSString *string) { static NSString * const kAFCharactersGeneralDel...

AFURLRequestSerialization

AFURLRequestSerialization是用来对发出的请求进行一些处理

AFPercentEscapedStringFromString方法将string里面的:#[]@!$&’()*+,;=字符替换成%

NSString * AFPercentEscapedStringFromString(NSString *string) {
  	static NSString * const kAFCharactersGeneralDelimitersToEncode = @":#[]@"; // does not include "?" or "/" due to RFC 3986 - Section 3.4
    static NSString * const kAFCharactersSubDelimitersToEncode = @"!$&'()*+,;=";
	
  	// 从可用字符替换删除掉:#[]@!$&'()*+,;=这些字符
    NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy];
    [allowedCharacterSet removeCharactersInString:[kAFCharactersGeneralDelimitersToEncode stringByAppendingString:kAFCharactersSubDelimitersToEncode]];

	// FIXME: https://github.com/AFNetworking/AFNetworking/pull/3028
    // return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];
	
  	// 声明批量处理的大小为50
    static NSUInteger const batchSize = 50;

    NSUInteger index = 0;
    NSMutableString *escaped = @"".mutableCopy;
	
  	// 循环将string里面:#[]@!$&'()*+,;=的字符替换成%
    while (index < string.length) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu"
        NSUInteger length = MIN(string.length - index, batchSize);
#pragma GCC diagnostic pop
        NSRange range = NSMakeRange(index, length);

        // To avoid breaking up character sequences such as 

                    
                
相关标签: iOS