PHP calls the interface to transmit json data using the post method

不言
Release: 2023-03-28 18:46:02
Original
3375 people have browsed it

This article mainly introduces the PHP calling interface to use the post method to transmit json data. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

First, convert the data into json format, then call the interface through the curl method and pass the parameters

The code is as follows:

$keyword = urlencode($_POST['keyword']);
$parameters = json_encode(array('keyWord'=>$keyword,'areaCode'=>'*'));
$post_data['appToken'] = "323ds7674354fds32fdsda60173";//随便写的
$post_data['parameters'] = $parameters;
$url = 'http://serde.com/compadddvd/index';//随便写的
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//用post方法传送参数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
Copy after login

Then just return the data.

Related recommendations:

php post json parameter transmission and reception processing method

The above is the detailed content of PHP calls the interface to transmit json data using the post method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template