I am trying to POST a user to a rails backed server but I am getting an odd error. When I press submit, I get a 404 error in the log and the read out that says the page does not exist. Like so:
Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 404" UserInfo=0xc03c140 {NSLocalizedRecoverySuggestion=<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<style type="text/css">
body { background-color: #fff; co...
Below, in the log it prints the failing url
AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0xc033300> { URL: http://example.herokuapp.com/users },
So the log clims that this page does not exist, yet if I copy and paste the url- the page does indeed exist, and I have already been able to post to it from the webview. For some reason afnetworking or the nsmutbleURLrequest is claiming the page doesn't exist, when it does... I mean I don't want to say that the computer is mistaken, but what's going on here? I've cleaned xcode and quit and nothing like that fixed this. Has anyone had this happen?
This is the code I am using to make the request:
+ (void)createUserWithUsername:(NSString *)signature
email:(NSString *)email
password:(NSString *)password
block:(void (^)(User *user))block
{
NSDictionary *parameters = @{@"signature": signature,
@"email": email,
@"password": password
};
[[APIClient sharedClient] postPath:@"/users" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
User *user = [[User alloc] initWithDictionary:responseObject];
if (block) {
block(user);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
if (block) {
block(nil);
}
}];
}
And this is what the json looks like from the succesful posts I've made from the web side
{"created_at":"2013-07-18T04:05:36Z","email":"grant@gmail.com","id":1,"signature":grant,"updated_at":"2013-07-18T04:05:36Z"}
So after using Charles to compare successful to failing post requests I see the failing posts get a 406 error. This error is probably correct because both successful and failing posts have the same post path. So I don't think its a 404 like it said before. But 406? In the log for the failing request there is no ref to a problem with the fact that its content-type is json.. This is the console log
headers {
"Cache-Control" = "no-cache";
"Content-Type" = "application/json; charset=utf-8";
Date = "Wed, 31 Jul 2013 17:24:53 GMT";
"Proxy-Connection" = "Keep-alive";
Server = "thin 1.5.1 codename Straight Razor";
"Set-Cookie" = "_gold_session=BAh7Basdfasdk; path=/; HttpOnly";
"Transfer-Encoding" = Identity;
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = c9c17573dde8b4767ba519aed6e04959;
"X-Runtime" = "0.008262";
"X-Ua-Compatible" = "IE=Edge,chrome=1";
} }}
2013-07-31 10:24:57.828 Gold[57543:a0b] User: (null)
Here is a comparison of the server logs from Charles, showing a failing post request and a successful one.
This is the request from a failing post from the iphone
POST /users HTTP/1.1
Host mysterious-5550.herokuapp.com
Content-Type application/json; charset=utf-8
Accept-Encoding gzip, deflate
Content-Length 40
Accept-Language en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
Accept application/json
Connection keep-alive
User-Agent Gold/1.0 (iPhone Simulator; iOS 7.0; Scale/2.00)
This is the failing response:
HTTP/1.1 406 Not Acceptable
Cache-Control no-cache
Content-Type application/json; charset=utf-8
Date Wed, 31 Jul 2013 18:26:12 GMT
Server thin 1.5.1 codename Straight Razor
Set-Cookie _gold_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFVEkiJTU2OGY2MWZhMzdmNzY2OGRjZGU0ZmQ1Y2Q5YmZiNzAxBjsAVA%3D%3D--3ab7521533c9e8f0f5b4a4d5da4d9f294bdeaba5; path=/; HttpOnly
X-Rack-Cache invalidate, pass
X-Request-Id 900d86dd0719d0a00eacf803e90fa780
X-Runtime 0.007971
X-Ua-Compatible IE=Edge,chrome=1
transfer-encoding chunked
Connection keep-alive
This is the request of a successful post from the web
POST /users HTTP/1.1
Host mysterious-5550.herokuapp.com
Content-Length 217
Cache-Control max-age=0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin http://mysterious-5550.herokuapp.com
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1580.0 Safari/537.36
Content-Type application/x-www-form-urlencoded
Referer http://mysterious-5550.herokuapp.com/users/sign_up
Accept-Encoding gzip,deflate,sdch
Accept-Language en-US,en;q=0.8
Cookie _gold_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTQ5MGY5MzMzMmNlMzkxZDI4NTllNDU0ZGQ0ZTE5MDg2BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMStZRTNwbGRKQ1VJWXY4aXZtbUMybGt3ejFLcnBZSU5zY053WEcwa2kydDg9BjsARg%3D%3D--2dd8e808965ccc2da457abc94c58c39d080f62ab
This is the response from a successful post from the web
HTTP/1.1 302 Moved Temporarily
Cache-Control no-cache
Content-Type text/html; charset=utf-8
Date Wed, 31 Jul 2013 18:30:11 GMT
Location http://mysterious-5550.herokuapp.com/
Server thin 1.5.1 codename Straight Razor
Set-Cookie _gold_session=BAh7CUkiD3NlFlvdSBoY88c959; path=/; HttpOnly
X-Rack-Cache invalidate, pass
X-Request-Id c94b3d921dfe451c562c171524b78b3f
X-Runtime 0.750712
X-Ua-Compatible IE=Edge,chrome=1
transfer-encoding chunked
Connection keep-alive
Though the content-types are different (text/html v json) I don't think this is the problem. Both types should be accepted - and usually xcode would say unexpected content type. Can you see anything else that is incompatible that might be causing the 406 error?