An HTTP header was found while tracking the request
Basic knowledge background:
1) The context of “expect: 100 continue”:
The purpose of designing 100 (continue) HTTP status code in http / 1.1 protocol is that before the client sends request message, http / 1.1 protocol allows the client to determine whether the server is willing to accept the message body sent by the client (based on request headers).
That is, the client and server allow the two sides to “shake hands” before the post (large) data. If the match is made, the client starts to send (large) data.
The reason for this is that if the client sends the request data directly, but the server rejects the request, this behavior will bring a lot of resource overhead.
The protocol requires http / 1.1 clients to:
If the client expects to wait for the response of “100 continue”, the request it sends must contain a header field of “expect: 100 continue”!
2) When libcurl sends data larger than 1024 bytes, enable the “expect: 100 continue” feature:
This is what Lawrence wrote in 2011:
When using curl for post, when the data to post is greater than 1024 bytes, curl does not directly send a post request, but is divided into two steps:
1. Send a request, including a “expect: 100 continue” header field, to ask whether the server is willing to receive data;
2. Post the data to the server after receiving the 100 continue response returned by the server;
This is libcurl’s behavior.
Therefore, there is a problem. Not all servers will answer 100 continue correctly. For example, lighttpd will return 417 “expectation failed”, which will cause logical errors,,
The solution is easy:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Expect:’));