You can use multipartFormRequestWithMethod to create a multipart PUT request with the required data.
For example, in AFNetworking v3.x:
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; NSError *error; NSURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"PUT" URLString:@"http://example.com/rest/api/" parameters:@{@"foo" : @"bar"} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { NSString *value = @"qux"; NSData *data = [value dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:data name:@"baz"]; } error:&error]; NSURLSessionDataTask *task = [manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { if (error) { NSLog(@"%@", error); return; }
If AFNetworking 2.x, you can use AFHTTPRequestOperationManager :
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSError *error; NSURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"PUT" URLString:@"http://example.com/rest/api/" parameters:@{@"foo" : @"bar"} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { NSString *value = @"qux"; NSData *data = [value dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:data name:@"baz"]; } error:&error]; AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"%@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"%@", error); }]; [manager.operationQueue addOperation:operation];
Having demonstrated how you can create such a query, it is worth noting that the servers will not be able to analyze them. Notably, PHP parses multiple POST requests, but not multipart PUT .
Rob
source share