-
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];//这里要将url设置为空,可以设置为空,也可以不设置为空
httpClient.parameterEncoding = AFJSONParameterEncoding; //这句话不可少
NSMutableDictionary *params=[[NSMutableDictionary alloc] init]; // 要传递的json数据是一个字典
[params setObject:UserID forKey:@"userId"];
[params setObject:[self.contDic objectForKey:@"weiboId" ] forKey:@"operateId"];
// 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数据到服务器
最新推荐文章于 2024-04-28 09:39:35 发布
NSString *pathStr=@"http://www.baidu.com" ;