求解,怎么用AFNetworking 2.0 发送JSON到服务器请求数据
1个回答
展开全部
发送请求:
- (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:@"确定"];
}];
}
。。。
- (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:@"确定"];
}];
}
。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询