예제 #1
0
파일: MyCurl.php 프로젝트: rainrain/my_proj
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
    public static function postRequest($url, array $data = array())
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // post数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // post的变量
        if ($data) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        $output = curl_exec($ch);
        curl_close($ch);
        //打印获得的数据
        return $output;
    }
}
//准备数据
$url = "http://localhost:8080/test/test.php";
//改文件有代码  print_r($_GET);         print_r($_POST)
$data = array('a' => 'b', 'c' => 'd', 8 => 666, 888);
//测试get方法
$result = MyCurl::getRequest($url, $data);
//测试post方法
$result = MyCurl::postRequest($url, $data);
//打印结果
var_dump($result);