Home  >  Article  >  Backend Development  >  php curl模拟post请求小实例_PHP

php curl模拟post请求小实例_PHP

WBOY
WBOYOriginal
2016-06-01 11:57:39838browse

本机:
复制代码 代码如下:
$uri = "http://www.a.com/test.php";//这里换成你服务器的地址
// 参数数组
$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);

远程服务器:
复制代码 代码如下:
if(isset($_POST['name'])){
 if(!empty($_POST['name'])){
  echo '您好,',$_POST['name'].'!';
 }
}

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