当前位置: 移动技术网 > IT编程>开发语言>PHP > php curl模拟post请求小实例

php curl模拟post请求小实例

2019年04月01日  | 移动技术网IT编程  | 我要评论
本机:
复制代码 代码如下:

<?php
$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);

远程服务器:
复制代码 代码如下:

<?php
if(isset($_post['name'])){
 if(!empty($_post['name'])){
  echo '您好,',$_post['name'].'!';
 }
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网