简体   繁体   English

iOS NSURLSession是否支持HTTP 100-continue?

[英]Does iOS NSURLSession support HTTP 100-continue?

When an HTTP request includes 当HTTP请求包含时

Expect: 100-continue

in the header, a special protocol is enabled. 在标头中,启用了一个特殊协议。 It's complicated, but useful. 这很复杂,但很有用。

In the experiments we've run, the iOS 8 version of NSURLSession does not seem to send this expect header by default. 在我们运行的实验中,默认情况下,iOS 8版本的NSURLSession似乎没有发送此期望标头。 We're still exploring whether including it explicitly works. 我们仍在探索是否明确包含它。

The only reference we can find in Apple documentation claims that 100-continue will work is for the predecessor to NSURLSession , which is NSURLConnection . 我们在Apple文档中可以找到的唯一参考声明100-continue将适用于NSURLSession NSURLConnection的前身。 It says

If you are uploading data to a compatible server, the URL loading system also supports the 100 (Continue) HTTP status code, which allows an upload to continue where it left off in the event of an authentication error or other failure†. 如果要将数据上载到兼容服务器,则URL加载系统还支持100(继续)HTTP状态代码,该代码允许在发生身份验证错误或其他故障†时从上次停止的位置继续上载。 To enable support for upload continuation, set the Expect: header on the request object to 100-continue. 要启用对上载继续的支持,请将请求对象上的Expect:标头设置为100-continue。

What I'd like help with 我想要帮助的是什么

In order of preference: 按优先顺序排列:

  1. Detailed information on how this works from Apple. 有关Apple如何运作的详细信息。
  2. Any information on how this works on iOS from anybody. 任何有关iOS如何在iOS上运行的信息。

I'm definitely interested in knowing how this works on OS X as well. 我非常有兴趣了解它在OS X上是如何工作的。


† I'm not sure that's even a good description of what should be happening with 100-continue, because IIUC one point is that the body of the request is large, and you'd rather send the request header, get it pre-approved by the server, and then start sending the body. †我不确定这甚至可以很好地描述100-continue应该发生什么,因为IIUC的一点是请求的主体很大,而你宁愿发送请求头,得到预先批准由服务器, 然后开始发送正文。


Appendix 附录

This is a useful link discussing the vagaries of how 100-continue should be handled. 是一个有用的链接,讨论如何处理100-continue的变幻莫测。

This is a decently useful dialog I found on a github issue, about trying this using NSURLConnection on OS X. 是我在github问题上找到的一个非常有用的对话框,关于在OS X上使用NSURLConnection进行尝试。

Yes, it explicitly works if you set the header yourself. 是的,如果您自己设置标题,它明确有效。 In fact, download tasks use it automatically without the need to set the header, if memory serves. 事实上,如果内存服务,下载任务会自动使用它,而无需设置标题。 By default, IIRC, other tasks do not, under the assumption that requests might not be idempotent. 默认情况下,IIRC,其他任务不会,假设请求可能不是幂等的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM