开发者

Setting time out for NSMutableURLRequest to custom time [duplicate]

开发者 https://www.devze.com 2023-03-12 12:34 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: NSMutableURLRequest timeout doesn't trigger if data starts to load but not webViewDidFinishLoad
This question already has answers here: Closed 11 years ago.

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 deleg开发者_高级运维ate: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;


You can set your time for timeOutSeconds like this:-

[myRequest setTimeOutSeconds:1000];

Set timeOutSecond according to yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消