在localhost根目錄建立1.php如下:
$ch=curl_init('http://localhost/post.php');
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
// localhost:8888是fiddler的代理,設置此選項用於讓fiddler抓獲post的請求
curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888');
//下面這一句必須注釋,不然Fiddler抓不到Post的http請求
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
//1.文件路徑之前必須要加@
//2.文件路徑帶中文就會失敗,例如'img_1'=>'@C:\Documents and Settings\Administrator\桌面\Android壁紙\androids.gif'
array('uname'=>'wqfghgfh','img_1'=>'@C:\Documents and Settings\Administrator\androids.gif')
);
$data=curl_exec($ch);
curl_close($ch);
echo $data;
?>
在localhost根目錄新建post.php如下
var_dump($_POST);
var_dump($_FILES);
?>
訪問http://localhost/1.php,返回如下內容:
array 'uname' => string 'wqfghgfh' (length=8) array 'img_1' => array 'name' => string 'androids.gif' (length=12) 'type' => string 'application/octet-stream' (length=24) 'tmp_name' => string 'C:\WINDOWS\Temp\php1BE.tmp' (length=26) 'error' => int 0 'size' => int 11293
