How to set HTTP request body using AFNetwork's AFHTTPRequestOperationManager?

前端 未结 7 1861
死守一世寂寞
死守一世寂寞 2020-12-13 14:49

I am using AFHTTPRequestOperationManager (2.0 AFNetworking library) for a REST POST request. But the manager only have the call to set the parameters.

-((         


        
7条回答
  •  星月不相逢
    2020-12-13 15:18

    If you dig a little in sources of AFNetworking you will find that in case of POST method parameters are set into body of your HTTP request.

    Each key,value dictionary pair is added to the body in form key1=value1&key2=value2. Pairs are separated by & sign.

    Search for application/x-www-form-urlencoded in AFURLRequestSerialization.m.

    In case of a string which is only a string, not key value pair then you might try to use AFQueryStringSerializationBlock http://cocoadocs.org/docsets/AFNetworking/2.0.3/Classes/AFHTTPRequestSerializer.html#//api/name/setQueryStringSerializationWithBlock: but this is only my guess.

提交回复
热议问题