AFNetworking设置请求头文件head

2019-12-23 18:28:05 浏览数 (3)

代码语言:javascript复制
    NSString *url = HOST_GAME;
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.requestSerializer = [AFJSONRequestSerializer serializer];
    session.responseSerializer = [AFJSONResponseSerializer serializer];
    [session.requestSerializer setValue:@"uuid=111222&channel=10001&appId=G0000000004&os=2&osVersion=1.0.0&md=iphoneX" forHTTPHeaderField:@"head"];
//    [session.requestSerializer setValue:@"zhelishiqingqiutou; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
//    NSLog(@"---%@",session.requestSerializer.HTTPRequestHeaders);
    [session POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *responseDict = [NSDictionary dictionaryWithDictionary:responseObject];
        NSString *code = [responseDict objectForKey:@"code"];
        NSDictionary *data = [responseDict objectForKey:@"data"];
        NSString *msg = [responseDict objectForKey:@"message"];
        if ([code  isEqual: @"200"])
        {
            NSLog(@"%@", data);
            NSLog(@"成功");
        }else{
            NSLog(@"%@", msg);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(@"失败");
    }];    

0 人点赞