Solution to php curl post error: First open the PHP code file with the error; then change the "$data" in the PHP code from an array to the data encoded by the "urlencode()" function.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Solution to the problem when php curl post Method
has the following scenario:
Submit data to b.php in a.php in POST mode, but b.php cannot receive the data, and the CURL operation It shows success again, which is very strange. It turns out that "when passing an array to CURLOPT_POSTFIELDS, cURL will encode the data into multipart/form-data, but when passing a URL-encoded string, the data will be encoded into application/x-www-form-urlencoded.".
When people who are not familiar with CURL write programs, the code often:
Code example:
<?php $data = array( 'Title' => $title, 'Content' => $content, 'ComeFrom' => $comefrom ); curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false); curl_setopt($ch, CURLOPT_URL, 'http://example.com/b.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch);
Convert the data to be submitted as an array The form is sent through POST, which will cause CURL to use the "wrong" encoding "multipart/form-data", which is equivalent to directly using "