This article will introduce to you the difference between arrays and strings used by PHP's CURLOPT_POSTFIELDS parameter. Friends who need to know more may feel free to refer to it.
PHP’s CURL component is a very commonly used HTTP request simulator.
Usually when sending post data, I have become accustomed to writing like this:
curl_setopt( $ch, CURLOPT_POSTFIELDS,$post_data);
But when sending a request to a certain server, the server returns 500. Use the socket method to connect to send requests and return normal data.
Try to send to a webpage with only . You can see that when using an array to send POST data, the CONTENT_TYPE received is as follows:
The code is as follows | Copy code | ||||
|
It can be seen that when CURLOPT_POSTFIELDS is set to an array, 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