HttpClient.DefaultRequestHeaders.ExpectContinue。 ExpectContinue的用途是什么,在什么条件下它被设置为true或false。 [英] HttpClient.DefaultRequestHeaders.ExpectContinue. What purpose does ExpectContinue serve and under what conditions is it set to true or false.

查看:2489
本文介绍了HttpClient.DefaultRequestHeaders.ExpectContinue。 ExpectContinue的用途是什么,在什么条件下它被设置为true或false。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览一些代码并且遇到过

I've been going through some code and have come across

  private readonly HttpClient _client;
 _client = new HttpClient(clientHandler);
 _client.DefaultRequestHeaders.ExpectContinue = false;

msdn( https://goo.gl/IoZlB1 )没有太多关于ExpectContinue的信息。此外,msdn上的HttpRequestHeader枚举( https://goo.gl/IoZlB1 )将Expect as描述为

The msdn (https://goo.gl/IoZlB1) doesn't contain much information about ExpectContinue. Also the HttpRequestHeader Enumeration on msdn (https://goo.gl/IoZlB1) describes Expect as


Expect标头,指定客户端需要
的特定服务器行为。

The Expect header, which specifies particular server behaviors that are required by the client.

我希望有人可以了解ExpectContinue。它的目的是什么以及如果它是真或假会发生什么?

I'm hoping if someone can shed some light on ExpectContinue. What is the purpose of it and what happens if it is true or false?

推荐答案

继续状态主要用于发送首先请求标头,以查看服务器是否允许(接受)请求。如果服务器显示OK,则发送100-continue,客户端继续请求正文。否则,服务器响应417(期望失败)。

The continue status is used mostly for sending the request headers first, to see if the server will allow (accept) the request. If the server says OK, it sends a 100-continue and the client proceeds with the request body. Otherwise, server responds with 417 (Expectation Failed).

认为您要将1 GB文件上载到服务器上的特定文件夹。如果您直接启动传输并且服务器不接受大于512 MB的文件或该文件夹不存在,则服务器将不接受该文件,并且传输将浪费双方的资源。

Think that you are going to upload a 1 GB file to a specific folder on a server. If you start the transfer directly and the server does not accept files bigger than 512 MB or the folder does not exist, the server will not accept the file, and the transfer will be a waste of resources for both sides.

检查W3C文档此处

参见8.​​2.3使用100(继续)状态

See section 8.2.3 Use of the 100 (Continue) Status

这篇关于HttpClient.DefaultRequestHeaders.ExpectContinue。 ExpectContinue的用途是什么,在什么条件下它被设置为true或false。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆