PHP CURL 模拟POST请求 提交数据或上传文件
1.http://www.a.com/a.php
发送POST请求
function execUpload(){
$file = "/doucment/Readme.txt";
$ch = curl_init();
$post_data = array(
"loginfield" => "username",
"username" => "ybb",
"password" => "123456",
"file" => "@d:usrwww ranslatedocumentReadme.txt"
);
curl_setopt($ch, CURLOPT_HEADER, false);
//启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_URL, "http://www.b.com/handleUpload.php");
$info= curl_exec($ch);
curl_close($ch);
print_r($info);
}
2.http://www.b.com/handleUpload.php
function handleUpload(){print_r($_POST);
echo "===file upload info:";
print_r($_FILES);
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。