1
我想利用這個curl.For我使用NUM []中的HTML代碼。此發送多個號碼作爲輸入的是我的代碼如何使用curl發送多個數字作爲輸入?
$num[]=$_POST["num"];
$msg=$_POST["msg"];
$url = 'http://localhost/s/a.php';
$fields = array(
'num'=>urlencode($_POST["num"]),
'msg'=>urlencode($_POST["msg"]));
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
$re = curl_exec($ch);
但它顯示了一個錯誤
Warning: urlencode() expects parameter 1 to be string, array given in
1.'$ _POST [ 「NUM」]'或'$ _POST [ 「NUM」]',任一或兩者都是陣列。 2.你爲什麼要做'$ num [] = $ _POST [「num」];'?您可以簡單地執行'$ num = $ _POST [「num」];' –
3.您不會在'$ re'中得到任何東西,除非您也設置了這個'curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);' 4.'CURLOPT_POST'沒有取整數值,比如'count($ fields)',它應該是'curl_setopt($ ch,CURLOPT_POST,true);' –
我已經解決了,謝謝 –