Home >Backend Development >PHP Tutorial >The difference between using arrays and strings in CURLOPT_POSTFIELDS of PHP cURL
We use the following two variables to do the cURL POST test:
<code><span><?php </span><span>// 数组</span><span>$arr_data</span> = [<span>'a'</span> => <span>'apple'</span>]; <span>// 字符串</span><span>$str_data</span> = <span>'{"a":"apple"}'</span>;</span></code>
Then the following is the result printed from the server side:
The above figure analyzes the difference between CURLOPT_POSTFIELDS using arrays and strings from $_SERVER[‘CONTENT_TYPE’], $
_POST variables, and php://input respectively.
Finally, we can conclude:
1) When using an array, the Content-Type of the HTTP request header will be set to multipart/form-data;
2) When using strings
The above has introduced the difference between using arrays and strings in CURLOPT_POSTFIELDS of PHP cURL, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.