我在web服务中发布参数。使用以下代码。我收到了"请求失败:不可接受(406)错误。我不确定是否正确发布。
我尝试使用POSTMAN chrome app使用键和值对发布数据。它在那里工作正常。请不要在这里建议。我第一次使用Afnetworking
[params setValue:self.txtUserName forKey:@"name"];
[params setValue:self.txtEmail forKey:@"mail"];
[params setValue:self.txtPass forKey:@"conf_mail"];
[params setValue:self.txtPass2 forKey:@"pass"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://charlie.indivar.info/ministore/store-commerce/user/register"
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Data"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
以下是控制台日志
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unacceptable (406)" UserInfo=0x8deb400 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x8ddddf0> { URL: http://website.com/ministore/store-commerce/user/register } { status code: 406, headers {
"Cache-Control" = "no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = "Keep-Alive";
"Content-Length" = 396;
"Content-Type" = "application/json";
Date = "Fri, 10 Oct 2014 07:06:40 GMT";
Etag = "\"1412924800\"";
Expires = "Sun, 19 Nov 1978 05:00:00 GMT";
"Keep-Alive" = "timeout=5, max=100";
"Last-Modified" = "Fri, 10 Oct 2014 07:06:40 +0000";
Server = Apache;
"Set-Cookie" = "SESSd5cd87b70f9ea9019d306d6f4e440b74=5lpY8-PvQYRM5IBWiGk33EeXsucAJCBZQSce7vRBhEY; expires=Sun, 02-Nov-2014 10:40:01 GMT; path=/; domain=website.com; HttpOnly";
Vary = Accept;
"X-Drupal-Cache" = MISS;
"X-Powered-By" = "PHP/5.3.10-1ubuntu3.14";
} }, NSErrorFailingURLKey=http://website.com/ministore/store-commerce/user/register, NSLocalizedDescription=Request failed: unacceptable (406), com.alamofire.serialization.response.error.data=
0a7b2273 74617475 73223a22 30222c22 64617461 223a7b22 6e616d65 223a2255 7365726e 616d6520 63616e6e 6f742062 65206c6f 6e676572 20746861 6e203630 20636861 72616374 65727320 62757420 69732063 75727265 6e746c79 20323031 20636861 72616374 65727320 6c6f6e67 2e222c22 6d61696c 223a2254 68652065 2d6d6169 6c206164 64726573 7320266c 743b5549 54657874 4669656c 643a2030 78386462 63306230 3b206672 616d6520 3d202835 37203135 343b2031 35332033 30293b20 74657874 203d2026 23303339 3b646565 70616b73 6f6f6440 64656570 616b2e63 6f6d2623 3033393b 3b20636c 69707354 6f426f75 6e647320 3d205945 533b206f 70617175 65203d20 4e4f3b20 6175746f 72657369 7a65203d 20524d2b 424d3b20 67657374 75726552 65636f67 6e697a65 7273203d 20266c74 3b4e5341 72726179 3a203078 38663665 38613026 67743b3b 206c6179 6572203d 20266c74 3b43414c 61796572 3a203078 38646165 65653026 67743b26 67743b20 6973206e 6f742076 616c6964 2e227d7d&gt;}
答案 0 :(得分:1)
如果Web服务器检测到它要返回的数据不是 客户端可以接受,它返回包含406错误的标头 码。 Web浏览器中很少发生此错误,因为大多数浏览器都会接受从Web服务器返回的任何数据。
看起来服务器无法识别您是移动设备等...