如何使用PHP cURL发布html多部分表单数据

时间:2012-05-07 09:49:17

标签: php html post curl

请帮我用PHP cURL

发布以下多部分表单数据
url = "http://smssheep.com/sendsms.php";
reffer="http://smssheep.com/";

POSTDATA =-----------------------------187161971819895
Content-Disposition: form-data; name="country"

0091
-----------------------------187161971819895
Content-Disposition: form-data; name="no"

00918714349616
-----------------------------187161971819895
Content-Disposition: form-data; name="msg"

hggggggggggggggggggggggggggggggggggggggggg
-----------------------------187161971819895
Content-Disposition: form-data; name="x_form_secret"

bqu9hv488bxu
-----------------------------187161971819895
Content-Disposition: form-data; name="saveForm"

SEND
-----------------------------187161971819895
Content-Disposition: form-data; name="comment"


-----------------------------187161971819895
Content-Disposition: form-data; name="idstamp"

Ds11xxs27YzNm/r/vf I rmQbz2TS1yaMNXeuHD6ozI=
-----------------------------187161971819895--

任何帮助都将是一个很大的帮助。

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

它与explained in the PHP manual完全相同:

$data = 'url = "http://smssheep.com/sendsms.php";
reffer="http://smssheep.com/";

POSTDATA =-----------------------------187161971819895
Content-Disposition: form-data; name="country"

...

Ds11xxs27YzNm/r/vf I rmQbz2TS1yaMNXeuHD6ozI=
-----------------------------187161971819895--'

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

答案 2 :(得分:1)

像这样

$url = "http://smssheep.com/sendsms.php";
$reffer="http://smssheep.com/";
$data = array(
        'country' => '0091',
        'no' => '00918714349616',
        'msg' => 'hggggggggggggggggggggggggggggggggggggggggg'       
        );


$data2 = http_build_query($data);

curl_setopt ($ch, CURLOPT_URL,$url); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data2); 
curl_setopt ($ch, CURLOPT_REFERER, $reffer);         

注意:在数组中必须是所有发布数据。