使用 NSURLConnection 强制 HTTP v1.0 请求

发布于 2024-07-20 16:10:31 字数 124 浏览 4 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

固执像三岁 2024-07-27 16:10:31

快速查看 NSURLRequest API 后,我没有看到任何从该级别执行此操作的方法,但您可以通过下拉到 CFNetwork.framework(Mac 上的 CoreServices.framework)中的 HTTPMessage API 来完成此操作。 例如:

CFHTTPMessageRef request = CFHTTPMessageCreateRequest( kCFAllocatorDefault,
    CFSTR("GET"), theURL, kCFHTTPVersion1_0 );

如果你想要一个 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:

CFHTTPMessageRef request = CFHTTPMessageCreateRequest( kCFAllocatorDefault,
    CFSTR("GET"), theURL, kCFHTTPVersion1_0 );

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.

淡紫姑娘! 2024-07-27 16:10:31

最新版本的 ASIHTTPRequest 有一个简单的方法可以做到这一点:

[request setUseHTTPVersionOne:YES];

The latest version of ASIHTTPRequest has an easy way to do this:

[request setUseHTTPVersionOne:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文