您的位置:首页 > 其它

使用AFNetworking框架进行post 请求解析返回得数据

2014-10-09 11:39 597 查看
2014/10/9

项目给出URL进行请求,先前一直用asi框架,但是一直请求失败,所以换了afnetworking框架

当点击页面button时进行网络请求 现在这是一个demo测试

- (void)buttonAction {

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

[dic setObject:@"liuyang"
forKey:@"LoginName"];

[dic setObject:@"123456"
forKey:@"Password"];

NSString *urlString = [NSString
stringWithFormat:url];

// NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager
manager];

// manager.responseSerializer = [AFJSONResponseSerializer serializer];

// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];

manager.requestSerializer = [AFJSONRequestSerializer
serializer];
[manager
POST:urlString parameters:dic
success:^(AFHTTPRequestOperation *operation,
id responseObject) {

NSLog(@"success%@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation,
NSError *error) {

NSLog(@"%@",error);
}];

}

// manager.responseSerializer = [AFJSONResponseSerializer serializer];

// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];

// 前两行没有注释掉得时候一直发生错误

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/json" UserInfo=0x7f8ba843f820 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse:
0x7f8ba843dfd0> { URL: http://192.168.1.96:102/Login? } { status code: 200, headers {

"Cache-Control" = "no-cache";
"Content-Length" = 472;
"Content-Type" = "application/json; charset=utf-8";
Date = "Thu, 09 Oct 2014 03:49:48 GMT";
Server = "Guri Aest Server, Ver:1.0.0.0 Microsoft-HTTPAPI/2.0";
"ga_tt" = "OwAAAAcRSOkRznBRM6feW9yPyr6kyZ8eLupWgVS0gWHPySxtb5Y1tvhw81tm1ablUy/VrJBFNKm1yMmj2lSOguDknLqgBOuW";
"ga_uid" = 43;
} }, NSErrorFailingURLKey=http://192.168.1.96:102/Login?, com.alamofire.serialization.response.error.data=<5b7b2253
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐