当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - NSURLConnection sendAsynchronousRequest: Long run on https

问题描述:

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

网友答案:

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

keepalive_timeout 0

in my nginx's config file.

分享给朋友:
您可能感兴趣的文章:
随机阅读: