Problems with php curl post resolved

  • 2020-12-20 03:30:26
  • OfStack

In ES0en.php, data is submitted to b.php in POST, but data cannot be received under b.php, and the CURL operation shows success, which is very weird. Originally, "If you pass an array to CURLOPT_POSTFIELDS, cURL encodes the data as multipart/ form-ES13en, but if you pass an URL-ES15en string, the data will be encoded as application/ x-ES18en-ES19en-ES20en.
People like me who are not familiar with CURL often write programs that look like this:


$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);


This means that the data to be submitted is sent via POST in the form of an array, which causes CURL to use the "wrong" encoding "multipart/ form-ES32en", which has the same effect as we send the" < form method="post" action="b.php" enctype="multipart/form-data" > "To complete the operation, you can try" b.php ", which cannot receive data through $_POST in any way.

So, the right thing to do is to change the $data in the sample code above from an array to an urlencode() encoded

Related articles: