Home > Backend Development > PHP Tutorial > PHP curl simulates post request small example_PHP tutorial

PHP curl simulates post request small example_PHP tutorial

WBOY
Release: 2016-07-13 10:25:15
Original
1005 people have browsed it

Local machine:

Copy code The code is as follows:

$uri = "http:// www.a.com/test.php"; // Replace this with the address of your server
// Parameter array
$data = array (
'name' => 'tanteng'
// 'password' => 'password'
);

$ch = curl_init ();
// print_r($ch);
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 );

print_r($return);

remote Server:
Copy code The code is as follows:

if(isset($_POST['name '])){
if(!empty($_POST['name'])){
echo 'Hello,',$_POST['name'].'! ';
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825169.htmlTechArticleNative: Copy the code as follows: ?php $uri = "http://www.a.com/ test.php"; // Replace this with the address of your server // Parameter array $data = array ( 'name' = 'tanteng' // 'password' = '...
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