美文网首页
AFnetworking post 添加请求头

AFnetworking post 添加请求头

作者: 水晶兰 | 来源:发表于2016-04-26 16:19 被阅读0次

利用manager.requestSerializer setValue:<#(NSString *)#> forHTTPHeaderField:<#(NSString *)#>添加请求头

key:Value

- (void)addRequest:(NSMutableDictionary *)parDic

url:(NSString *)url

completionBlock:(completeBlock)comletionBlock{

//  [self getSign:parDic];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

//申明返回的结果类型

manager.responseSerializer = [AFJSONResponseSerializer serializer];

//申明请求的数据类型

manager.requestSerializer=[AFHTTPRequestSerializer serializer];

manager.requestSerializer.timeoutInterval = 30;

//af设置请求头

//manager.requestSerializer setValue:<#(NSString *)#> forHTTPHeaderField:<#(NSString *)#>

[manager POST:[self fullUrl:url]

parameters:parDic

success:^(AFHTTPRequestOperation *operation,id responseObject) {

NSDictionary *resultDic = (NSDictionary *)responseObject;

if (comletionBlock) {

comletionBlock(resultDic, nil);

}

}failure:^(AFHTTPRequestOperation *operation,NSError *error) {

NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"-1001",@"JJ_TAG_PARAM_R_CODE",@"JJ_ERROR_MSG",@"JJ_TAG_PARAM_R_MSG", nil];

if (comletionBlock) {

comletionBlock(dict,error);

}

}];

}

相关文章

网友评论

      本文标题:AFnetworking post 添加请求头

      本文链接:https://www.haomeiwen.com/subject/hbnqrttx.html