iphone - 将 NSMutableURLRequest 超时设置为自定义时间

标签 iphone objective-c ios cocoa-touch nsmutableurlrequest

<分区>

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

我正在使用异步 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];

我正在实现以下委托(delegate):

- (void)connection:(NSURLConnection *)iConnection didReceiveResponse:(NSURLResponse *)iResponse;
- (void)connection:(NSURLConnection *)iConnection didReceiveData:(NSData *)iElementContructionContextData;
- (void)connection:(NSURLConnection *)iConnection didFailWithError:(NSError *)iError;

最佳答案

您可以像这样设置 timeOutSeconds 的时间:-

[myRequest setTimeOutSeconds:1000];

根据自己设置timeOutSecond。

关于iphone - 将 NSMutableURLRequest 超时设置为自定义时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6339283/

相关文章:

javascript - iPhone:修复了返回时 div 粘在页面中间的问题 "history.back(-1)"

iphone - 为什么 NSMutableDictionary 不想写入文件?

iphone - 继续 session 到游戏包中的下一个 View

iphone - TTStyledTextLabel 的 url 字体

ios - 如何正确子类化 UIActionSheet

Objective-c IOS 重复 UILocalNotification 设置为过去的日期

ios - iOS6 上的自动布局问题 : "All dependent constraints should have been removed from the engine and also from the view' s list of dependent constraints"

ios - 如何一次弹出两个/三个 View watchKit 应用程序?

iphone - 获取 EXC_BAD_ACCESS 但我不知道为什么

ios - 尝试在手势识别时翻转单元格上的 ImageView ,代码工作正常但没有翻转