Afnetworking 2.0 parameter encoding

2019-08-04 09:13发布

问题:

Hi i am using afnetworking 2.0 in my project. I need to post with json dic as parameter. In earlier version afhttpclient there is AFJSONParameterEncoding. How to do it in latest version?

回答1:

Right now you need to use serializer classes for your reuqest manager

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];