What's the correct way to code a multipart PUT request using AFNetworking on iOS? (still Objective-C, not Swift)
I looked and seems like AFNetworking can do multipart POST
but not PUT
, what's the solution for that?
Thanks
What's the correct way to code a multipart PUT request using AFNetworking on iOS? (still Objective-C, not Swift)
I looked and seems like AFNetworking can do multipart POST
but not PUT
, what's the solution for that?
Thanks
.h
.m:
Just like the classic afnetworking. Put it to your net work Util :)
You can create an NSURLRequest constructed with the
AFHTTPRequestSerialization
's multipart form request methodHere is code for Afnetworking 3.0 and Swift that worked for me. I know its old thread but might be handy for someone!
You can use
multipartFormRequestWithMethod
to create a multipartPUT
request with desired data.For example, in AFNetworking v3.x:
If AFNetworking 2.x, you can use
AFHTTPRequestOperationManager
:Having illustrated how one could create such a request, it's worth noting that servers may not be able to parse them. Notably, PHP parses multipart
POST
requests, but not multipartPUT
requests.I came up with a solution that can handle any supported method. This is a solution for PUT, but you can replace it with POST as well. This is a method in a category that I call on the base model class.
Aso it uses FileWrapper Interface
For RAW Body :
NSData *data = someData; NSMutableURLRequest *requeust = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[self getURLWith:urlService]]];