1:创建NSMutableURLRequest
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
URLString:(NSString *)URLString
parameters:(id)parameters
error:(NSError *__autoreleasing *)error
{
//---增加断言当一下参数为空的时候停止程序并打印错误日志
NSParameterAssert(method);
NSParameterAssert(URLString);
NSURL *url = [NSURL URLWithString:URLString];
//如果根据传入的参数创建出来的url为空则停止程序打印错误日志
NSParameterAssert(url);
//通过以上断言,成功通过之后根据正确的url创建mutableRequest对象
NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:url];
//设置mutableRequest的请求方式(GET、POST、HEAD、DELETE、PUT等)
mutableRequest.HTTPMethod = method;
/*
设置mutableRequest的属性 AFHTTPRequestSerializerObservedKeyPaths()函数创建参数数组
①allowsCellularAccess 是否允许使用蜂窝网络
②cachePolicy 缓存策略
1:NSURLRequestUseProtocolCachePolicy (默认的缓存策略,如果本地缓存不存在,直接从服务端获取。如果缓存存在,会根据response中的Cache-Control字段判断下一步操作,如: Cache-Control字段为must-revalidata, 则询问服务端该数据是否有更新,无更新的话直接返回给用户缓存数据,若已更新,则请求服务端)
2:NSURLRequestReloadIgnoringLocalCacheData (忽略本地缓存数据,直接请求服务端)
3:NSURLRequestReloadIgnoringLocalAndRe