AFNetworking 如何POST一个JSON数据到服务器
2013-07-05 11:28
387 查看
NSString *pathStr=@"http://www.baidu.com" ;
AFHTTPClient *httpClient = [[AFHTTPClient
alloc] initWithBaseURL:[NSURL
URLWithString:@""]];//这里要将url设置为空
httpClient.parameterEncoding =
AFJSONParameterEncoding;
[httpClient setDefaultHeader:@"Accept"
value:@"text/json"];
NSMutableDictionary *params=[[NSMutableDictionary
alloc] init]; // 要传递的json数据是一个字典
[params setObject:UserID
forKey:@"userId"];
[params setObject:[self.contDic
objectForKey:@"weiboId" ]
forKey:@"operateId"];
[params setObject:@"8d0ce196d0eafa27780cc3a7217de71d92474021dc0a4fc593d4f9b9eda320ca"
forKey:@"key"];
// httpClient 的postPath就是上文中的pathStr,即你要访问的URL地址,这里是向服务器提交一个数据请求,
[httpClient postPath:pathStr
parameters:params
success:^(AFHTTPRequestOperation *operation,
id responseObject) {
NSLog(@"data====%@",params);
NSString *responseStr = [[NSString
alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
NSLog(@"Request Successful, response '%@'", responseStr);
[responseStr release];
} failure:^(AFHTTPRequestOperation *operation,
NSError *error) {
NSLog(@"[HTTPClient Error]: %@", error);
}];
AFHTTPClient *httpClient = [[AFHTTPClient
alloc] initWithBaseURL:[NSURL
URLWithString:@""]];//这里要将url设置为空
httpClient.parameterEncoding =
AFJSONParameterEncoding;
[httpClient setDefaultHeader:@"Accept"
value:@"text/json"];
NSMutableDictionary *params=[[NSMutableDictionary
alloc] init]; // 要传递的json数据是一个字典
[params setObject:UserID
forKey:@"userId"];
[params setObject:[self.contDic
objectForKey:@"weiboId" ]
forKey:@"operateId"];
[params setObject:@"8d0ce196d0eafa27780cc3a7217de71d92474021dc0a4fc593d4f9b9eda320ca"
forKey:@"key"];
// httpClient 的postPath就是上文中的pathStr,即你要访问的URL地址,这里是向服务器提交一个数据请求,
[httpClient postPath:pathStr
parameters:params
success:^(AFHTTPRequestOperation *operation,
id responseObject) {
NSLog(@"data====%@",params);
NSString *responseStr = [[NSString
alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
NSLog(@"Request Successful, response '%@'", responseStr);
[responseStr release];
} failure:^(AFHTTPRequestOperation *operation,
NSError *error) {
NSLog(@"[HTTPClient Error]: %@", error);
}];
相关文章推荐
- AFNetworking 如何POST一个JSON数据到服务器
- AFNetworking如何post一个json数据到服务器
- AFNetworking如何post一个json数据到服务器
- AFNetworking如何post一个json数据到服务器
- AFNetworking如何post一个json数据到服务器
- AFNetworking 如何POST一个JSON数据到服务器
- AFNetworking 如何POST一个JSON数据到服务器
- 如何POST一个JSON格式的数据给Restful服务
- iOS开发往服务器Post一个json数据
- 如何POST一个JSON格式的数据给Restful服务
- 实习第一天——做一个录音上传服务器的小功能pttp协议post发送文件和参数到服务器,解析返回的json数据
- 一个好用的测试服务器接口的工具(post请求,xml,json等数据格式)
- 如何向php服务器发送数据为json的post请求
- 如何POST一个JSON格式的数据给Restful服务
- 如何使用PHP调用API接口( 如何POST一个JSON格式的数据给Restful服务)
- 如何POST一个JSON格式的数据给Restful服务
- 如何使用JSON格式 POST数据到服务器
- 如何POST一个JSON格式的数据给Restful服务
- JQuery以POST方法从ASP.NET服务器获取Json数据完整示例
- Ajax获取PHP服务器上的 Json数据以及POST的综合实例