RestTemplate、PUT 方法和 Expect:100-CONTINUE
我是 Resttemplate 以及 Apache http 类如何支持它的新手。因此,一开始我认为我需要做的就是使用 Expect: 100 Continue 手动创建 http 标头,以便开始使用该功能实现 PUT 方法。就我而言,与我进行对话的服务器响应正确,但我的应用程序从未看到 100-Continue 响应,因为 100-Continue 被忽略,如下所示: [org.apache.commons.httpclient.HttpMethodBase] - < '丢弃意外响应:HTTP/1.1 100 继续>。 Wireshark 确认我收到了 100 Continue。
在阅读了一些内容之后,我现在明白了,我必须在某个地方设置 PUT 方法的默认行为才能使用 Expect: 100-Continue 标头...并且我开始认为它在任何 Springsource 编写的类中都没有。据我所知,相关的Apache抽象类是:org.apache.commons.httpclient.methods.ExpectContinueMethod,它有一个名为org.apache.commons.httpclient.methods.PutMethod的子类,并且无论如何都有一个setter在所有 PUT 请求中使用 Expect: 100-CONTINUE。
所以现在这就引出了两个问题: 1.
我如何设置此功能,以便我可以在与服务器的对话中使用 100-CONTINUE?我一直在 Springsource 文档中搜索,我看到了 HttpClientParams 的设置位置以及 CommonsClientHttpRequestFactory 的设置方式,但是当 Resttemplate 作用于 PUT 请求时,我不知道在哪里或如何设置 ExpectContinueMethod 的使用。我开始认为在任何 Springsource 类或包中都不可能......我感觉resttemplate 的级别太高了,可以这么说。
也许我必须导入许多 Apache 包来实例化它们并指定 ExpectContinue 功能的使用,并以某种方式确保 Resttemplate 和其他 Springsource 类使用它们(如果可能或有意义的话)。今天这超出了我的能力范围,但我对需要做什么有一个模糊的概念。即使这是真的,这是否意味着对于任何应用程序,我必须选择永远对所有 PUT 请求使用 100-Continue 标头?我不能让某些 PUT 请求使用它,而其他请求则不依赖于主体的大小?这太糟糕了。
即使是指向正确方向的指针也会受到赞赏。
——保罗
I'm a newbie to resttemplate and how it is backed by Apache http classes. So at first I thought all I needed to do was manually create http headers with Expect: 100 Continue in order to start implementing a PUT method using that feature. In my case the server with which I was having a dialogue responded correctly but my application never saw the 100-Continue response because the 100-Continue is being ignored, as such: [org.apache.commons.httpclient.HttpMethodBase] - <'Discarding unexpected response: HTTP/1.1 100 Continue>. Wireshark confirms I got the 100 Continue.
I understand now after doing some reading that somewhere I must set the default behavior of the PUT method to use the Expect: 100-Continue header...and I'm starting to think its nowhere in any Springsource authored class. As far as I can tell the relevant Apache abstract class is: org.apache.commons.httpclient.methods.ExpectContinueMethod, which has a sublclass called org.apache.commons.httpclient.methods.PutMethod, and in any event has a setter for using Expect: 100-CONTINUE in all PUT requests.
So this leads to 2 questions now, now 1.
How can I set this feature so I can use 100-CONTINUE in my dialogues with servers? I've been searching within Springsource documentation and I see where the HttpClientParams are set and how for the CommonsClientHttpRequestFactory, but I'm at a loss of where or how to set the use of ExpectContinueMethod when resttemplate acts on a PUT request. I'm starting to think it is not possible from within any Springsource class or package...I'm getting the feeling resttemplate is just too high level, so to speak.
Perhaps I have to import many Apache packages just to instantiate them and specify the use of the ExpectContinue feature, and somehow make sure resttemplate and other Springsource classes use them (if that is even possible or makes sense). Today that's over my head but I have a vague notion of what needs to be done. Even if true, does this mean that for any application I must choose to either use the 100-Continue header for all PUT requests forever? I cannot have some PUT requests use it and others not depending on, say, the size of the body? This would be terrible.
Even a pointer in the correct direction would be appreciated.
-Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论