參考文章?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; // 單位是秒垮兑,設(shè)置3分鐘超時
? ? for (NSString *keyPath in AFHTTPRequestSerializerObservedKeyPaths()) {
? ? ? ? if ([self.mutableObservedChangedKeyPaths containsObject:keyPath]) {
? ? ? ? ? ? [mutableRequestsetValue:[selfvalueForKeyPath:keyPath]forKey:keyPath];
? ? ? ? }
? ? }
? ? mutableRequest = [[selfrequestBySerializingRequest:mutableRequestwithParameters:parameterserror:error]mutableCopy];
returnmutableRequest;
}