<?php $uri = "http://www.cnblogs.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); 2,远程服务器: <?php if(isset($_POST['name'])){ if(!empty($_POST['name'])){ echo '您好,',$_POST['name'].'!'; } }
以上就介紹了php curl模擬post請求的範例程式碼,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。