Home>Article>Backend Development> How to solve curl php post loss problem

How to solve curl php post loss problem

藏色散人
藏色散人 Original
2021-07-13 09:22:49 1989browse

php curl post data is lost because in the string type, the & symbol is used to separate parameters, so it will cause loss. The solution is to submit it using Array.

How to solve curl php post loss problem

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

How to solve the curl php post loss problem?

About the problem of data loss in PHP Curl POST

$ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $uri ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); $return = curl_exec ( $ch ); curl_close ( $ch );

$data parameters have two types: string/array

For example: we want to submit two data

$title = '我是标题'; $content = '点我百度一下';

When the type is string

$data = 'title=这是标题&content=点我百度一下';

After submission, we will find that $_POST['content'] does not appear as we want1552f1ccb0bfbba19f5dd9237290201eClick on Baidu5db79b134e9f6b82c0b36e0489ee08ed, butArray( [title] => 我是标题 [content] => 点我百度一下 )

At this time, we only need to use Array to submit and there will be no problem

Recommended learning : "

PHP Video Tutorial"

The above is the detailed content of How to solve curl php post loss problem. For more information, please follow other related articles on the PHP Chinese website!

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