使用 NSURLConnection 强制 HTTP v1.0 请求
NSURLConnection 默认使用 HTTP v1.1 执行 GET 请求。
如何让它使用 HTTP v1.0 执行 GET 请求?
或者我可以设置一个 HTTP 标头来为我完成此操作吗?
NSURLConnection by default performs a GET request with HTTP v1.1.
How do I get it to perform a GET request with HTTP v1.0?
Or is there a HTTP header I can set that will do this for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速查看 NSURLRequest API 后,我没有看到任何从该级别执行此操作的方法,但您可以通过下拉到 CFNetwork.framework(Mac 上的 CoreServices.framework)中的 HTTPMessage API 来完成此操作。 例如:
如果你想要一个 ObjC 包装器来解决这个问题,有一些可用的,包括 我自己的一个设计。 它是 CF API 的一个相当基本的包装器,但您可以从中获取一个 NSInputStream,您可以使用它来使用标准 NSInputStream API 读取响应数据。
其他的,例如 ASIHTTPRequest 提供了更大的 API,您可能更喜欢。
After a quick look through the NSURLRequest APIs I don't see any way of doing this from that level, but you can do it by dropping down to the HTTPMessage APIs in CFNetwork.framework (CoreServices.framework on the Mac). For instance:
If you want an ObjC wrapper around this, there are a few available, including one of my own devising. That one is a fairly basic wrapper around the CF API, but you can get an NSInputStream from it which you can use to read the response data using the standard NSInputStream APIs.
Others, such as ASIHTTPRequest provide a much larger API, which you might prefer.
最新版本的 ASIHTTPRequest 有一个简单的方法可以做到这一点:
The latest version of ASIHTTPRequest has an easy way to do this: