1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
function posturl($url, $data = array()) { $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if (1 == strpos("$" . $url, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } if (!is_array($data)) {
$headers = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); }
curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($curl);
curl_close($curl);
return json_decode($res, true); }
|