首页 > Web开发 > 详细

cURL模拟POST方式提交数据

时间:2015-11-20 17:12:30      阅读:152      评论:0      收藏:0      [点我收藏+]

curl_post.php文件:

 1 $url = ‘http://localhost/test/curl_post_deal.php‘;
 2 
 3 $post_data = array(
 4     ‘username‘ => ‘cURL‘,
 5     ‘age‘ => ‘18‘,
 6     ‘sex‘ => ‘male‘
 7 );
 8 $ch = curl_init();
 9 
10 curl_setopt($ch, CURLOPT_URL, $url);        //请求的地址
11 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//如果成功,只将结果返回,不自动输出任何内容,如果失败返回false
12 curl_setopt($ch, CURLOPT_POST, 1);            //设置请求为post类型
13 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//post发送的数据
14 
15 $response = curl_exec($ch);    //执行post请求,获得回复
16 var_dump($response);
17 
18 curl_close($ch);

curl_post_deal.php文件:

1 print_r($_POST);

结果:

string

 ‘Array
(
    [username] => cURL
    [age] => 18
    [sex] => male
)
‘ (length=67)

cURL模拟POST方式提交数据

原文:http://www.cnblogs.com/cloak/p/4981024.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!