Under normal circumstances, when we use CURL to submit POST data, we are used to writing it like this:
curl_setopt( $ch, CURLOPT_POSTFIELDS,$post_data);
But this writing method is not very useful sometimes, and may get a 500 error returned by the server. But when we try to use Socket to submit data to the server, we will get very correct results.
For example, we have the following PHP file on the server:
<?php print_r($_SERVER);?>
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:
[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:
[CONTENT_TYPE] => application/x-www-form-urlencoded
From above It is not difficult to see from this 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