欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP通过Post提交数据

程序员文章站 2022-05-16 19:54:41
...
  1. $postData = array();
  2. $postData['data1'] = "testdata1";
  3. $postData['data2'] = "testdata2";
  4. $postData['data3'] = "testdata3";
  5. $url='http://yourdomain/do.php';
  6. $str="";
  7. foreach ($postData as $k=>$v)
  8. {
  9. $str.= "$k=".urlencode($v)."&";
  10. }
  11. $postData=substr($str,0,-1);
  12. $c = curl_init();
  13. curl_setopt($c, CURLOPT_POST, 1);
  14. curl_setopt($c, CURLOPT_HEADER, 0);
  15. curl_setopt($c, CURLOPT_URL,$url);
  16. curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
  17. $result = curl_exec($c);
复制代码

PHP, Post