Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting time out for NSMutableURLRequest to custom time [duplicate]

Possible Duplicate:
NSMutableURLRequest timeout doesn't trigger if data starts to load but not webViewDidFinishLoad

I am using a Async HTTP request and setting timeout for my NSMutableURLRequest to 30 seconds and I want to timeout the request within this time.

Problem: Request is not getting timed out withing 30 seconds. It is always taking 90 seconds to timeout. Any solution for this.

Here is my code for connection:

NSMutableURLRequest *myRequest = [[NSMutableURLRequest alloc] initWithURL:myURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
[myRequest setHTTPMethod:@"POST"];
[myRequest setHTTPBody:myData];

NSURLConnection *myConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];

And I am implementing following delgates:

- (void)connection:(NSURLConnection *)iConnection didReceiveResponse:(NSURLResponse *)iResponse;
- (void)connection:(NSURLConnection *)iConnection didReceiveData:(NSData *)iElementContructionContextData;
- (void)connection:(NSURLConnection *)iConnection didFailWithError:(NSError *)iError;
like image 259
Abhinav Avatar asked Jun 14 '11 05:06

Abhinav


1 Answers

You can set your time for timeOutSeconds like this:-

[myRequest setTimeOutSeconds:1000];

Set timeOutSecond according to yourself.

like image 56
Gypsa Avatar answered Nov 18 '22 06:11

Gypsa