Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500), got 2960324" #1379

Closed
sankaet opened this Issue Sep 28, 2013 · 18 comments

Projects

None yet
@sankaet
sankaet commented Sep 28, 2013

I just updated my AFnetworking to 2.0 (using iOS 6 +)

My initial code was

//Some POST
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://myurl.herokuapp.com/"]];


NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:username,password, nil] forKeys:[NSArray arrayWithObjects:@"username",@"password", nil ]];

[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
[httpClient postPath:@"api/v1/checkedin/" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject){

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

I changed that to

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];


NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:username,password, nil] forKeys:[NSArray arrayWithObjects:@"username",@"password", nil ]];

[manager POST:@"https://myurl.herokuapp.com/api/v1/checkedin/" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

and now my request is not going through. It says

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500), got 2960324" UserInfo=0x15554780 {NSErrorFailingURLKey=https://aqueous-sea-1455.herokuapp.com/api/v1/checkedin/, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x156705c0> { URL: https://aqueous-sea-1455.herokuapp.com/api/v1/checkedin/} { status code: 500, headers {
    Connection = "keep-alive";
    "Content-Length" = 1285;
    "Content-Type" = "application/json";
    Date = "Fri, 27 Sep 2013 23:59:17 GMT";
    Server = "gunicorn/18.0";
} }, NSLocalizedDescription=Request failed: internal server error (500), got 2960324}

Am I doing something wrong?

Also, I keep on getting the following warnings

screen shot 2013-09-27 at 7 06 30 pm

Contributor
xHunter commented Sep 28, 2013

In your AFHTTPClient example you are setting the default encoding to AFJSONParameterEncoding, by default AFHTTPRequestOperationManager uses AFHTTPRequestSerializer so you need set the requestSerializer.

manager.requestSerializer = [AFJSONRequestSerializer serializer];
sankaet commented Sep 28, 2013

Oh! I didn't know about that. what about the warnings I keep on getting though?

@mattt mattt added a commit that referenced this issue Sep 29, 2013
@mattt mattt [Issue #1379] Adding missing code macros for iOS 6 compatibility in U…
…IAlertView category
0604cfd
Contributor
mattt commented Sep 29, 2013

Thanks, @xHunter.

@sankaet Those are caused by a missing iOS versioning macro. This is fixed by 0604cfd.

@mattt mattt closed this Sep 29, 2013

Why would the default request serializer be AFHTTPRequestSerializer but the default response serializer be AFJSONResponseSerializer? Seems inconsistent, and also seems to be a change from how 2.0.0.-RC3 worked (default req serializer was json).

Relevant code from AFHTTPRequestOperationManager, lines 59-60:

self.requestSerializer = [AFHTTPRequestSerializer serializer];
self.responseSerializer = [AFJSONResponseSerializer serializer];
Contributor
mattt commented Sep 30, 2013

@jamieforrest It's inconsistent in so far as a change from RC 3, but since request and response serialization are orthogonal concerns, it's not entirely out of place. Every server / web framework knows how to speak URL form-encoded HTTP, but a good number won't handle a JSON body properly without further configuration.

@haikusw haikusw added a commit to haikusw/AFNetworking that referenced this issue Sep 30, 2013
@mattt @haikusw mattt + haikusw [Issue #1379] Adding missing code macros for iOS 6 compatibility in U…
…IAlertView category
9ed95b7

@mattt I am currently working with a service that returns a 400 unless you send it a JSON-formatted body. I understand your reasoning though.

Anyone getting here searching for the Code=-1011 red herring, this is the answer: http://stackoverflow.com/a/19450191/822164, better yet http://nshipster.com/nserror/

Hi,

Even i am getting same error, here is my code

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:baseUrl parameters:parameters];

[request setValue:@"application/x-www-form-urlencoded; charset=UTF8" forHTTPHeaderField:@"Content-Type"];

AFHTTPRequestOperation *op = [manager HTTPRequestOperationWithRequest:request success: ^(AFHTTPRequestOperation *operation, id responseObject)
{

    DLog(@"response: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
    DLog(@"Error: %@", error);
}];
op.responseSerializer = [AFHTTPResponseSerializer serializer];
[[NSOperationQueue mainQueue] addOperation:op];

and i am getting response as

{ status code: 400, headers {
"Alternate-Protocol" = "80:quic";
"Cache-Control" = private;
"Content-Type" = "text/html; charset=utf-8";
Date = "Mon, 17 Mar 2014 13:18:44 GMT";
Server = "Google Frontend";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
} }, NSLocalizedDescription=Request failed: bad request (400), got 73832}

I also met this problem

I also face same problem how did you solve?
Reason: Request failed: bad request (400).

Also im getting same error -

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo=0x15d4c7d0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17069fe0> { URL: http://test.shipler.in/api/v2/auth/verify_pin/ } { status code: 400, headers {
Connection = close;
"Content-Type" = "application/json";
Date = "Fri, 21 Aug 2015 07:37:43 GMT";
Server = "Apache/2.4.7 (Ubuntu)";
"Transfer-Encoding" = Identity;
Vary = Cookie;
"X-Frame-Options" = SAMEORIGIN;

@greghe greghe pushed a commit to skillz/AFNetworking that referenced this issue Sep 3, 2015
@mattt mattt [Issue #1379] Adding missing code macros for iOS 6 compatibility in U…
…IAlertView category
1984b1e
yuenhe commented Sep 16, 2016

按时到

xyfqldy commented Oct 20, 2016 edited

@PatilManoj1717 how did you solve this question . I encounter the same problem ,and it's the same 'bad request(400)' . For many solution ,they say add this line manager.responseSerializer = [AFHTTPResponseSerializer serializer]; ,But i had added it . Can you tell me, appreciate.

me too

me too

me too

Any idea how to get the status code value? from there?

I soved this problem like:

manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 
manager.requestSerializer = [AFJSONRequestSerializer serializer];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment