参考文章 https://www.shuzhiduo.com/A/n2d9DXn05D/
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
URLString:(NSString*)URLString
parameters:(id)parameters
error:(NSError*__autoreleasing*)error
{
NSParameterAssert(method);
NSParameterAssert(URLString);
NSURL*url = [NSURLURLWithString:URLString];
NSParameterAssert(url);
NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:url];
mutableRequest.HTTPMethod= method;
mutableRequest.timeoutInterval=180; // 单位是秒,设置3分钟超时
for (NSString *keyPath in AFHTTPRequestSerializerObservedKeyPaths()) {
if ([self.mutableObservedChangedKeyPaths containsObject:keyPath]) {
[mutableRequestsetValue:[selfvalueForKeyPath:keyPath]forKey:keyPath];
}
}
mutableRequest = [[selfrequestBySerializingRequest:mutableRequestwithParameters:parameterserror:error]mutableCopy];
returnmutableRequest;
}