Similar to this issue.
Using AFNetworking 2.0.3 and trying to upload an image using AFHTTPSessionManager\'s POST + constructingBodyWithBlock. For reasons unknown, it se
Digging into this further, it appears that when you use NSURLSession
in conjunction with setHTTPBodyStream
, even if the request sets Content-Length
(which AFURLRequestSerialization
does in requestByFinalizingMultipartFormData
), that header is not getting sent. You can confirm this by comparing the allHTTPHeaderFields
of the task's originalRequest
and currentRequest
. I also confirmed this with Charles.
What's interesting is that Transfer-Encoding
is getting set as chunked
(which is correct in general when the length is unknown).
Bottom line, this seems to be a manifestation of AFNetworking's choice to use setHTTPBodyStream
rather than setHTTPBody
(which doesn't suffer from this behavior), which, when combined with NSURLSession
results in this behavior of malformed requests.
I think this is related to AFNetworking issue 1398.