当前位置 : 主页 > 网络编程 > PHP >

PHP通过Post提交数据

来源:互联网 收集:自由互联 发布时间:2021-07-03
$postData = array();$postData['data1'] = "testdata1";$postData['data2'] = "testdata2";$postData['data3'] = "testdata3";$url='http://yourdomain/do.php';$str="";foreach ($postData as $k=$v){ $str.= "$k=".urlencode($v)."";}$postData=substr($st
$postData = array();
$postData['data1'] = "testdata1";
$postData['data2'] = "testdata2";
$postData['data3'] = "testdata3";
$url='http://yourdomain/do.php';
$str="";
foreach ($postData as $k=>$v)
{
    $str.= "$k=".urlencode($v)."&";
}
$postData=substr($str,0,-1);
$c = curl_init();
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_URL,$url);
curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($c);
网友评论