Search code examples
iphoneioshttpsnsurlrequest

NSURLRequest setHTTPBody ending up in parameters of the server


I am trying to send a POST request to my server, everything seems to be working fine, however all of the HTTPBody is ending up in the parameters of the request at the server end.

There is a Self-Signed certificate on the server which generates a AuthenticationChallenge that I am currently ignoring, thats working fine also.

However as I stated above the postBodyData is ending up in the wrong place on the server. The code I am using is showen below and is documented in Apples ios documentation library under NSURLRequest.

[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody:postBodyData];

any help, suggestions or examples would be appreciated.


Solution

  • Okay, Have figured out the issue. Because I was sending Binary data the content type was wrong, once i passed in an empty string it worked.

    However I did not want to have no content type set so I have found a MIME type that works for this correctly as showed below.

    [request setValue:@"application/octet-stream" forHTTPHeaderField:@"content-type"];