使用AFNetworking框架進行post 請求解析返回得資料
2014/10/9
專案給出URL進行請求,先前一直用asi框架,但是一直請求失敗,所以換了afnetworking框架
當點選頁面button時進行網路請求 現在這是一個demo測試
- (void)buttonAction {
NSMutableDictionary *dic = [[NSMutableDictionaryalloc] init];
[dic setObject:@"liuyang"forKey:@"LoginName"];
[dic setObject:@"123456"forKey:@"Password"];
NSString *urlString = [
// NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
// manager.responseSerializer = [AFJSONResponseSerializer serializer];
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
manager.requestSerializer = [AFJSONRequestSerializerserializer];
[manager POST:urlString parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success%@"
} 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