This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12455|Reply: 1

HTTP request header Expect is explained in detail

[Copy link]
Posted on 2021-4-22 15:32:09 | | |
Document Introduction:The hyperlink login is visible.

When calling the other party's interface through curl, it was found that the timeout phenomenon was very serious, so I asked the other party's interface person, and the other party said that it was necessary to add:


After adding it, I found that it really worked well, so I researched how to use it. When using curl for POST, when "POST data is greater than 1024 bytes", curl will not directly initiate a POST request, but will be divided into 2 steps:

Expect: 100-continue

1. Send a request containing an Expect:100-continue, asking the server to accept the data

2. After receiving the 100-continue reply returned by the Server, the data is POSTed to the Server

But there are several problems with this:

Not all servers will correctly respond to 100-continue, e.g. lighttpd, which will return 417 Expectation Failed.

causing delay,When the client sends the first Expect:100-continue, it needs to wait for the server to answer before sending the request body

If you are sure that the other party's server will not reject POST requests of more than 1024 bytes, you can avoid using this method and avoid the two side effects mentioned above, and the solution is the one mentioned at the beginning of the article.

About 100 continue

The purpose of this is to:

It allows the client to judge whether the server is willing to receive the request data before sending it, and if the server is willing to receive it, the client will actually send the data.

Client behavior:

A client that sends 100 continue should not wait forever for a response from the server, and after a period of timeout, the client should send the entity directly.

Server-side behavior:

If the server receives a 100 continue request, it will respond with 100 continue or send an error code. The server can never send 100 continue to a client that does not send 100 continue. But some servers do. IIS 5 incorrectly sending 100-continue response

If the server receives the client's body before sending the 100 continue response, it means that the client has decided to start sending data, so the server can no longer send 100 continue to the client.
The .NET Expect Off Expect setting code is as follows:

RestSharp is set up as follows:







Previous:The difference between utf8 and utf8mb4 in MySQL
Next:SignalR adds cross-domain support for remote access
 Landlord| Posted on 2025-4-6 21:52:04 |
HttpClient closing method


or

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com