AFN利用cookie POST JSON服务器接收不到参数

来源:互联网 发布:阿里巴巴客户顾问知乎 编辑:程序博客网 时间:2024/06/06 18:27

首先抱怨下,这个问题搞的我焦头烂额,搞了一天,从各种百度,从刚开始的传输cookie,再到后来的POST json。以为AFN可以很好的解决这些问题,其实大家错误的利用了

 [session POST:URLparameters:dicsuccess:^(NSURLSessionDataTask *_Nonnull task,id _Nonnull responseObject) {       

        }

    } failure:^(NSURLSessionDataTask * _Nullable task,NSError *_Nonnull error) {

    }];

将传入的参数nsutf8编码,所以服务器总是找不到这些参数。

最后利用原始的网络请求顺利的解决了这个问题:

NSMutableURLRequest *request = [[AFJSONRequestSerializerserializer]requestWithMethod:@"POST"URLString:URLparameters:dicerror:nil];

    [NSURLConnectionsendAsynchronousRequest: request queue: [NSOperationQueuemainQueue]

                           completionHandler: ^(NSURLResponse *response, NSData *data,NSError *error){

              if (error) {


              NSLog(@"Httperror: %@%ld", error.localizedDescription, error.code);

            

            } else {


            NSJSONSerialization *json = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:nil];

             NSDictionary *dicjson = (NSDictionary *)json;

             NSLog(@"%@",dicjson);

                 

                 }

     }];

希望对有同样错误的TX有所帮助。