码迷,mamicode.com
首页 > Web开发 > 详细

curl的简单使用

时间:2016-01-06 23:16:35      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $uri = "http://localhost/test/index.php/Home/Index/test";
        // 参数数组
        $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, 0 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
        $return = curl_exec ( $ch );
        curl_close ( $ch );
         
        //dump($return);die;
                //$this->display();
    }
   
   public function test(){
        if(isset($_POST[‘name‘])){
            if(!empty($_POST[‘name‘])){
                echo ‘您好,‘,$_POST[‘name‘].‘!‘;
            }
        }
    }
}

效果:

技术分享

curl的简单使用

标签:

原文地址:http://www.cnblogs.com/hltswd/p/5107759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!