标签:
Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 406"
{ status code: 406,headers {
"Content-Language" = en;
"Content-Length" = 1110;
"Content-Type" = "text/html;charset=utf-8";
Date = "Sat, 27 Sep 2014 05:29:13 GMT";
Server = "Apache-Coyote/1.1";
} }
+ (NSSet *)acceptableContentTypes
{
return [NSSet setWithObjects:@"text/html", @"text/plain", @"application/json", @"text/json", @"text/javascript", nil];
}
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
+ (NSSet *)acceptableContentTypes
{
return [NSSet setWithObjects:@"text/html", @"text/plain", @"application/json", @"text/json", @"text/javascript", nil];
}
+ (void)postWithBaseURL:(NSString *)baseURL path:(NSString *)path
params:(NSDictionary *)params success:(HttpSuccessBlock)success
failure:(HttpFailureBlock)failure
{
// 封装请求
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:baseURL]];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client setDefaultHeader:@"Accept" value:@"application/json"];
NSURLRequest *post = [client requestWithMethod:@"POST" path:path parameters:params];
// 创建AFJSONRequestOperation对象
NSOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:post success:^(NSURLRequest *request,
NSHTTPURLResponse *response, id JSON) {
success(JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
failure(error);
}];
// 发送请求
[operation start];
}
+(void)getWithBaseURL:(NSString *)baseURL path:(NSString *)path
params:(NSDictionary *)params success:(HttpSuccessBlock)success
failure:(HttpFailureBlock)failure
{
// 封装请求
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:baseURL]];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client setDefaultHeader:@"Accept" value:@"application/json"];
NSURLRequest *post = [client requestWithMethod:@"GET" path:path parameters:params];
// 创建AFJSONRequestOperation对象
NSOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:post success:^(NSURLRequest *request,
NSHTTPURLResponse *response, id JSON) {
success(JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
failure(error);
}];
// 发送请求
[operation start];
}
AFNetworkingErrorDomain 错误解决方法
标签:
原文地址:http://www.cnblogs.com/bugismyalllife/p/4897405.html