Home  >  Article  >  Backend Development  >  Solution to the problem when php curl post

Solution to the problem when php curl post

WBOY
WBOYOriginal
2016-07-25 08:54:38920browse
  1. $data = array( 'Title' => $title, 'Content' => $content, 'ComeFrom' => $comefrom );
  2. curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE , false);
  3. curl_setopt($ch, CURLOPT_URL, 'http://example.com/b.php');
  4. curl_setopt($ch, CURLOPT_POST, 1);
  5. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  6. curl_exec($ch);
Copy code

Send the data to be submitted in the form of an array through POST, and this will cause CURL to use the "wrong" encoding "multipart/form-data", which The effect is equivalent to directly completing the operation with a form like "

". You can try it. At this time, "b.php" cannot receive data through $_POST anyway.

So, the correct approach should be to change $data in the above code from an array to one encoded by urlencode().



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn