HttpClient.DefaultRequestHeaders.ExpectContinue. W

2019-07-20 01:10发布

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

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

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

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

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?

1条回答
We Are One
2楼-- · 2019-07-20 02:14

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).

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.

Check the W3C documentation here

See section 8.2.3 Use of the 100 (Continue) Status

查看更多
登录 后发表回答