2012-04-30 147 views
0

我正在尝试为NSMutableURLRequest设置超时值,并且在调试时检查了它不工作。谷歌搜索了10分钟,我得到的信息,默认超时值是240。以下是这,我使用的是现在的代码,我想我缺少的地方,我想知道如何使用这个太[_nsmURLRequest initWithURL:nsURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120];设置超时值的NSMutableURLRequest设置NSMutableURLRequest的超时值

NSURL *url = [[NSURL alloc] initWithString:fURL]; 

_urlRequest = [[NSMutableURLRequest alloc] url]; 
[_urlRequest setHTTPMethod:@"GET"]; 
[_urlRequest setTimeoutInterval:120]; 

NSURLConnection* _urlConnection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate: self]; 

我都试过了。它不工作。任何帮助将感激

+0

看看它可以帮助http://stackoverflow.com/questions/1466389/nsmutableurlrequest-timeout-interval-not-taken-into-consideration-for-post -reque/27962981#27962981 –

回答

-1

根据this发布默认超时值(240)您提到的也是最小值。您必须使用另一个计时器来取消链接中所述的请求。

+0

您不应该使用计时器,请参阅[评论和回答](http://stackoverflow.com/questions/8304560/how-to-set-a-timeout-with-afnetworking#comment12884403_8304560)by [ @matt](http://stackoverflow.com/users/157142/mattt)([AFNetworking](https://github.com/AFNetworking/AFNetworking)的作者)。 – DanSkeel

0

尝试移动setTimeoutInterval前的我的答案setHTTPMethod:@"GET"

+1

以上听起来更像是[评论](http://stackoverflow.com/help/privileges/comment)。如果它的目的是成为一个答案,考虑增加一些更详细的信息来解释它是如何解决问题的。 – Leigh