Heim  >  Artikel  >  Backend-Entwicklung  >  php程序内部post数据的方法_PHP

php程序内部post数据的方法_PHP

WBOY
WBOYOriginal
2016-05-30 14:59:301021Durchsuche

本文实例讲述了php程序内部post数据的方法。分享给大家供大家参考。具体实现方法如下:

$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);

希望本文所述对大家的php程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn