您的位置:首页 > 编程语言 > PHP开发

PHP CURL 模拟POST请求 提交数据或上传文件

2012-09-07 17:27 661 查看
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:\usr\www\translate\document\Readme.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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: