本文介绍了CFNetwork HTTP超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为CFHTTP请求添加超时的方法。似乎应该有 CFHTTPMessage CFReadStream 对象的功能,但我找不到它。我是否必须在运行循环中滚动自己的计时器? (如果是这样,任何代码?)

I am looking for a way to add a timeout to a CFHTTP request. It seems like there should be a feature of the CFHTTPMessage or the CFReadStream object, but I can't find it. Do I have to roll my own timer on the run loop or something? (if so, any code for this?)

谢谢!

推荐答案

NSURLRequest 中包含的大部分功能。您可以使用 NSURLRequest requestWithURL指定超时:cachePolicy:timeoutInterval:

Update: ASIHTTPRequest is outdated and no longer maintained. I would now recommend either using Apple's built in NSURLConnection. NSURLConnection has a very small asynchronous API with most of the functionality contained in NSURLRequest. you can specify your timeout using NSURLRequest's requestWithURL:cachePolicy:timeoutInterval:

除非你有使用CFHTTPMessage的特殊原因,否则我建议使用更高级别的课程,例如,为您提供更多易用性,包括超时。

Unless you have a special reason for using CFHTTPMessage I'd recommend using a higher level class such as ASIHTTPRequest which gives you added ease of use including timeouts.

这篇关于CFNetwork HTTP超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:27