We use these two variables to do the Curl post test separately:
// 数组$arr_data = ['a' => 'apple'];// 字符串$str_data = '{"a":"apple"}';
Then the following is the result of printing from the server side:
The above diagram parses the CURLOPT_POSTFIELDS difference between using an array and a string, respectively, from $ _server[' Content_Type ', $ _post variable, and php://input.
Finally, we can conclude that:
1) when using the array
- HTTP request Header Content-type will be set to Multipart/form-data;
- The contents of the array can be obtained from $_post;
- Using File_get_content ("Php://input") is empty, and for this, the PHP manual also says:
Php://input isn't available with enctype= "Multipart/form-data"
2) when using a string
- HTTP request Header Content-type will be set to application/x-www-form-urlencoded;
- The string content becomes the key of an element inside the $_post;
- The string contents can be obtained from the php://input completely;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP curl Curlopt_postfields the use of arrays and string differences, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.