Why is loading AFNetworking NSMutableURLRequest always delayed?

I cannot use AFNetworking NSMutableURLRequest

to load the image - it always turns off.

I can make successful requests GET

to the same server:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

      

But it AFNetworking NSMutableURLRequest

always expires. My code looks like this:

// 1. Create AFHTTPRequestSerializer which will create your request.
AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];

// 2. Create an NSMutableURLRequest.
NSMutableURLRequest *request =
[serializer multipartFormRequestWithMethod:@"POST" URLString:@"http://192.168.0.105/upload2.php"
                                parameters:nil
                 constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                     [formData appendPartWithFileData:imageData
                                                 name:@"upfile"
                                             fileName:@"file://Users/wangyan/Downloads/idcard.png"
                                             mimeType:@"image/jpeg"];
                 }];

// 3. Create and use AFHTTPRequestOperationManager to create an AFHTTPRequestOperation from the NSMutableURLRequest that we just created.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *operation =
[manager HTTPRequestOperationWithRequest:request
                                 success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                     NSLog(@"Success %@", responseObject);
                                 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                     NSLog(@"Failure %@", error.description);
                                 }];

// 4. Set the progress block of the operation.
[operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
                                    long long totalBytesWritten,
                                    long long totalBytesExpectedToWrite) {
    NSLog(@"Wrote %ld/%ld", (long)totalBytesWritten, (long)totalBytesExpectedToWrite);
}];

// 5. Begin!
[operation start];

      

Here is the error I am getting:

Error with error Domain = NSURLErrorDomain Code = -1001 "The request timed out." UserInfo = 0x7fab1ada7d30
    {NSUnderlyingError = 0x7fab1ad7de00 "Request timed out."
     NSErrorFailingURLStringKey = http://192.168.0.105/upload2.php ,
     NSErrorFailingURLKey = http://192.168.0.105/upload2.php ,
     NSLocalizedDescription = Request timeout.}

I can't find any problems on the server. Any suggestions?

+3


source to share





All Articles