Under normal circumstances, when we use CURL to submit POST data, we are accustomed to writing like this:
Copy code The code is as follows:
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
But this way of writing is not very useful sometimes, and you may get a 500 error returned by the server. But when we try to submit data to the server using Socket, we will get very correct results.
For example, we have the following PHP file on the server:
Copy the code The code is as follows:
When we use CURL to send some data to the server without paying attention to details, we may get the following results, which is not our ideal result:
Copy code The code is as follows:
[CONTENT_TYPE] => multipart/form-data; boundary=——————————-f924413ea122
But if we use http_build_query($post_data) instead of $post_data and then submit data to this PHP script, we will get different results from the above. This is our ideal result:
Copy code The code is as follows:
[CONTENT_TYPE] => application/x-www-form-urlencoded
From It is not difficult to see from the above example that when using CURL and the parameter is data, when submitting data to the server, the HTTP header will send Content_type: application/x-www-form-urlencoded. This is the header sent by the browser when submitting the form on a normal web page