php curl模拟post请求小实例
时间:2020-10-05 21:32:51|栏目:PHP代码|点击: 次
本机:
<?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'].'!';
}
}
复制代码 代码如下:
<?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'].'!';
}
}
上一篇:Laravel解决nesting level错误和隐藏index.php的问题
栏 目:PHP代码
下一篇:php时区转换转换函数
本文标题:php curl模拟post请求小实例
本文地址:http://www.codeinn.net/misctech/7126.html