Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 406" javascript
{ status code: 406,headers {html
"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";
} }java
+ (NSSet *)acceptableContentTypesjson
{
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 *)acceptableContentTypesapp
{
return [NSSet setWithObjects:@"text/html", @"text/plain", @"application/json", @"text/json", @"text/javascript", nil];
}post
+ (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];
}spa