应该工作正常。
$data = array('name' => 'Ross', 'php_master' => true);// You can POST a file by prefixing with an @ (for <input type="file"> fields)$data['file'] = '@/home/user/world.jpg';$handle = curl_init($url);curl_setopt($handle, CURLOPT_POST, true);curl_setopt($handle, CURLOPT_POSTFIELDS, $data);curl_exec($handle);curl_close($handle)这里有两个选项,
CURLOPT_POST它们打开HTTP POST,并
CURLOPT_POSTFIELDS包含要提交的数组数组。可用于向
POST
<form>s 提交数据。
重要的是要注意,
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);$
data采用两种格式,并且这决定了将如何编码邮政数据。
$data
asarray()
:数据将以multipart/form-data
服务器并不总是接受的方式发送。$data = array('name' => 'Ross', 'php_master' => true);curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$data
作为url编码的字符串:数据将以形式发送application/x-www-form-urlenpred
,这是提交的html表单数据的默认编码。$data = array('name' => 'Ross', 'php_master' => true);curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data));
我希望这可以帮助其他人节省时间。
看到:
curl_init
curl_setopt



