is there an example of AFHTTPClient posting json with AFNetworking?

前端 未结 3 730
长情又很酷
长情又很酷 2021-02-05 22:56

Looking for an example of how to post json with AFHTTPClient. I see that there is a postPath method which takes an NSDictionary and the AFJSONEncode me

3条回答
  •  醉梦人生
    2021-02-05 23:42

    If you're posting to a JSON REST API, there should be a particular mapping from object property to JSON key, right? That is, the server is expecting certain information in certain named fields.

    So what you want to do is construct an NSDictionary or NSMutableDictionary with the keys used in the API and their corresponding values. Then, simply pass that dictionary into the parameters argument of any request method in AFHTTPClient. If the parameterEncoding property of the client is set to AFJSONParameterEncoding, then the body of the requests will automatically be encoded as JSON.

提交回复
热议问题