AFN坑及常用设置

1.AFN默认参数拼接在url后的请求有

self.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", @"DELETE", nil];

2.如果不想让AFN默认的请求参数拼接在url后面可以设置 self.HTTPMethodsEncodingParametersInURI 的值

if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) {
        if (query && query.length > 0) {
            mutableRequest.URL = [NSURL URLWithString:[[mutableRequest.URL absoluteString] stringByAppendingFormat:mutableRequest.URL.query ? @"&%@" : @"?%@", query]];
        }
    } else {
        // #2864: an empty string is a valid x-www-form-urlencoded payload
        if (!query) {
            query = @"";
        }
        if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) {
            [mutableRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        }
        [mutableRequest setHTTPBody:[query dataUsingEncoding:self.stringEncoding]];
    }

如果 是post的话就会走外面 如果是delete的话就会走if里面所以我想 是不是可以 设置HTTPMethodsEncodingParametersInURI这个属性来操作params使其不拼接
3.根据后台请求的方式,封装单例时设置Content-Type属性,AFN默认的属性为application/x-www-form-urlencoded,此时给body传值时,对象必须转成NSData,如果不想转成NSData,则修改Content-Type值为application/json即可

你可能感兴趣的:(AFN坑及常用设置)