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

PHP curl simulates post request small example_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:15977browse

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' = '...
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