求解,怎么用AFNetworking 2.0 发送JSON到服务器请求数据

如题所述

发送请求:
- (void)sendUpdateUserRequest

{

//添加等待

[MBProgressHUD showHUDWithText:@"正在更新,请稍候···"

toView:self.navigationController.view animated:YES];

NSMutableDictionary *headDict=[[NSMutableDictionary alloc] init];

NSMutableDictionary *dataDict=[[NSMutableDictionary alloc] init];

//组装数据,只是一个例子,可以添加你想要的属性以及值

[headDict setObject:@"user" forKey:@"function"];

[dataDict setObject:_useridLabel.text forKey:@"userid"];

//要发送的数据

NSDictionary *jsonDict=[NSDictionary

dictionaryWithObjectsAndKeys:headDict,@"head",dataDict,@"data",nil];

AFHTTPRequestOperationManager *httpRequestOperationManager=[AFHTTPRequestOperationManager manager];

//发送请求

[httpRequestOperationManager POST:gbUrlString parameters:jsonDict

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

//成功,你这里可以做你想要的事情

//关闭等待

[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];

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

//关闭等待

[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];

//给出提示

[BF showSysAlert:@"提示" message:@"服务器连接异常" cbTitle:@"确定"];

}];

}
温馨提示:答案为网友推荐,仅供参考
相似回答