php curl模拟post请求小实例

前端之家收集整理的这篇文章主要介绍了php curl模拟post请求小实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本机:
<div class="codetitle"><a style="CURSOR: pointer" data="34666" class="copybut" id="copybut34666" onclick="doCopy('code34666')"> 代码如下:

<div class="codebody" id="code34666">
<?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,CURLOPT_POSTFIELDS,$data );
$return = curl_exec ( $ch );
curl_close ( $ch );print_r($return);

远程服务器:
<div class="codetitle"><a style="CURSOR: pointer" data="26380" class="copybut" id="copybut26380" onclick="doCopy('code26380')"> 代码如下:
<div class="codebody" id="code26380">
<?PHP
if(isset($_POST['name'])){
if(!empty($_POST['name'])){
echo '您好,',$_POST['name'].'!';
}
}

原文链接:https://www.f2er.com/php/25428.html

猜你在找的PHP相关文章