0

I am trying to switch from http to https for some server API calls right now and I am having a problem with it that I cannot explain to myself.

Right after switching from http to https I am experiencing that my async request takes the full 60 seconds to finish, despite the fact that the server has already handled the request.

There is no error being thrown, no timeout occurring or anything like that, it just seems to take the full 60 seconds to notice that the request is finished. And then, after 60 seconds, it does just what it's meant to do.

This is what I am doing:

NSString *theBody = @"param1=value1&param2=value2";
NSData *bodyData = [theBody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:@"https://my.api.server.com/call"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];

[request setValue:@"My User-Agent" forHTTPHeaderField:@"User-Agent"];
// Tested this one, too. Yes, I did set to utf8 encoding when trying this
// [request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:bodyData];
// testing only
// [request setTimeoutInterval:15];

[NSURLConnection sendAsynchronousRequest:request 
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           NSLog(@"Finished!");
                       }];

The log message is thrown after 60 seconds. When refreshing the corresponding data before the log message is put out, I can see that everything's already happened - I can pull the refreshed data correctly.

I already thought it was my server taking so long for answering, but I have tried the same request using Ruby as a quick test run and it worked correctly.

Does anyone know what could be happening here?

Thanks in advance

Arne

arnekolja
  • 1,687
  • 5
  • 22
  • 29
  • what happens when you post to another server? just for testing? post to google on https or so... I would guess your server has a malfunction – Jonas Schnelli Apr 15 '12 at 18:22
  • You may be right. But there's a fun fact: When the request is not successful, it works. Well, at least it doesn't take the 60 seconds, but returns immediately. I am returning a JSON response on my server. If the call is successful, it returns code 201 (entity created ok) and JSON for the object. If it is not successful, it returns code 4xx and JSON with the error messages. Error works immediately, success takes NSURLConnection to take 60 seconds to finish - but it finishes correctly after this duration. – arnekolja Apr 15 '12 at 18:36
  • I just tried using delegation instead of the block again and I got this one working now. But how the heck is this possible? Is it a bug in iOS 5.1 that 201 isn't recognized as a response code? Can't explain it … any ideas? – arnekolja Apr 15 '12 at 19:25
  • Aaand the whole thing back again. It is not working. didReceiveData is being called, but didFinishLoading takes the 60 seconds to fulfill. I'll update my post with the new data. – arnekolja Apr 15 '12 at 20:40

1 Answers1

0

It seems to be a server issue actually. I fixed it by setting

keepalive_timeout 0

in my nginx's config file.

arnekolja
  • 1,687
  • 5
  • 22
  • 29