cURL模拟POST方式提交数据
生活随笔
收集整理的這篇文章主要介紹了
cURL模拟POST方式提交数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
curl_post.php文件:
1 $url = 'http://localhost/test/curl_post_deal.php'; 2 3 $post_data = array( 4 'username' => 'cURL', 5 'age' => '18', 6 'sex' => 'male' 7 ); 8 $ch = curl_init(); 9 10 curl_setopt($ch, CURLOPT_URL, $url); //請求的地址 11 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//如果成功,只將結果返回,不自動輸出任何內容,如果失敗返回false 12 curl_setopt($ch, CURLOPT_POST, 1); //設置請求為post類型 13 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//post發送的數據 14 15 $response = curl_exec($ch); //執行post請求,獲得回復 16 var_dump($response); 17 18 curl_close($ch);curl_post_deal.php文件:
1 print_r($_POST);結果:
string
'Array ([username] => cURL[age] => 18[sex] => male ) ' (length=67)轉載于:https://www.cnblogs.com/cloak/p/4981024.html
總結
以上是生活随笔為你收集整理的cURL模拟POST方式提交数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大学生数学建模竞赛心得(提高篇) 转
- 下一篇: jeesite使用心得(二)