Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Post - Time Out - Multiple Request getting initiated within timeout interval

Tags:

http

post

ios

I am using HTTP Post method and initiating a synchronous request. [NSURLConnection sendSynchronousRequest: ..]

For HTTP POST requests, the default time out is happening at 75 seconds as discussed in many threads.

But during that time out period of 75 seconds, Multiple web service requests are getting initiated for us for the same request raised with all the same parameters.

Please let us know What causes this multiple requests to get initiated? Is this due to HTTP POST in general or because of Synchronous request?

@iOS Sample Code

[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField: @"Content-Length"];

 [[NSURLCache sharedURLCache] setDiskCapacity:0];
 [[NSURLCache sharedURLCache] setMemoryCapacity:0];

 NSURLResponse *response;
 response = nil;

 urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];              
 if(urlData)
 {
        NSString *responseString = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
        [self parseStringInformation:responseString infoDict:informationDictionary];
        //NSLog(@"%@",responseString);
 }
like image 306
Subi Avatar asked Nov 07 '12 09:11

Subi


1 Answers

Without the server's request-response logs there are several possibilities.

Programmer Error: Have you already gone through all of "gotchya" type situations?

  • Have you put a logging message right before your "urlData = [NSURLConnection sendSynchronousRequest: ..." line to make sure your code is only calling it once?

  • Are you calling this function from within your main GUI thread, if you are that's not supported/recommended, which means it could be causing side-effects like what you're describing. https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

  • Are you sure your Request is set up as a POST and has the proper headers like "Content-type: multipart/form-data, boundary=X"

Web Server Responses: Without the web servers logs (or the code for the service your POSTing to) it's hard to say...

  • Perhaps your server is sending cyclical redirects to the client. If you don't implement a "connection:willSendRequest" then the redirects could be followed for ?X? amount of times for one request. http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/urlloadingsystem/Articles/RequestChanges.html

API Error: You've found some corner case which is causing unwanted side effects. Maybe apple has an bug tracker or developer support forum?

  • If this is the case you'll have to work around the bug, until it's fixed. I suggest implementing the Asynchronous call chain. "Loading Data Asynchronously" https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html
like image 103
Louis Ricci Avatar answered Nov 10 '22 20:11

Louis Ricci