可能重复:
NSMutableURLRequest timeout doesn't trigger if data starts to load but not webViewDidFinishLoad
我正在使用Async HTTP请求并将我的NSMutableURLRequest的超时设置为30秒,我希望在此时间内超时请求。
问题:请求没有超时30秒。超时始终需要90秒。任何解决方案。
这是我的连接代码:
NSMutableURLRequest *myRequest = [[NSMutableURLRequest alloc] initWithURL:myURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
[myRequest setHTTPMethod:@"POST"];
[myRequest setHTTPBody:myData];
NSURLConnection *myConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];
我正在实施以下指南:
- (void)connection:(NSURLConnection *)iConnection didReceiveResponse:(NSURLResponse *)iResponse;
- (void)connection:(NSURLConnection *)iConnection didReceiveData:(NSData *)iElementContructionContextData;
- (void)connection:(NSURLConnection *)iConnection didFailWithError:(NSError *)iError;
答案 0 :(得分:5)
您可以设置timeOutSeconds的时间,如下所示: -
[myRequest setTimeOutSeconds:1000];
根据你自己设定timeOutSecond。