發表文章

目前顯示的是有「post」標籤的文章

[PHP] curl post

使用curl post傳送/取回資料 //虛擬網址 $url = 'https://www.test.com'; //要post過去的值 $post_arr = array('name' => 'joy', 'email' => 'joy@gmail.com'); $ch = curl_init(); //curl init curl_setopt($ch, CURLOPT_URL, $url); //設定連線網址 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')); //設定header curl_setopt($ch, CURLOPT_POST, true); //啟用post curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_arr)); //傳入post參數 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //使用https網址, 而無法正常運作時, 要加這個 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //使用https網址, 而無法正常運作時, 要加這個 $result = curl_exec($ch); //執行, 送出post並將結果存回 curl_close($ch); //關閉連線 參考資料: https://blog.johnsonlu.org/php-curl/