使用AFNetworking 2.0 請求資料時出現錯誤 Request failed: unacceptable content-type: text/html 解決方法
新增一行
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
即可
整個程式碼為:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; NSDictionary *parameters = @{@"foo":@"bar"}; [manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@",responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error:%@",error); }];