Example on using AFNetworking to post XML?

2019-07-20 06:15发布

问题:

As a followup to this question, I cannot get this to work so I need to take a step back I think.

Can someone post some sample code on how to post XML to a rest service WITHOUT using params? Is it even possible? Basically I have an object with several properties, and I convert this to XML and then need to upload it. But it fails if there is an image converted to string in the XML. Without that it works fine.

Even a JSON example would be helpful...

Totally blocked here :P

回答1:

Use NSMutableURLRequest -setHTTPBody:, and set the Content-Type HTTP header to application/xml.

If you're doing this consistently, you may want to consider subclassing AFHTTPClient to add an XML parameter serialization option.