Created
June 8, 2018 06:43
-
-
Save landzz/882ed1a9826928e18a065fa0a532e930 to your computer and use it in GitHub Desktop.
php curl post function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists('getCurlPost')){ | |
function getCurlPost($_url='', $_param=array()){ | |
if($_url !=''){ | |
ini_set("memory_limit", "512M"); | |
$_headers = array( | |
"Content-Type: application/x-www-form-urlencoded; charset=utf-8" | |
); | |
$curlObj = curl_init(); | |
curl_setopt($curlObj, CURLOPT_URL, $_url ); | |
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curlObj, CURLOPT_SSLVERSION, 1); | |
curl_setopt($curlObj, CURLOPT_POST, true); | |
curl_setopt($curlObj, CURLOPT_HEADER, false); | |
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $_headers); | |
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curlObj, CURLOPT_POSTFIELDS, http_build_query($_param)); | |
$response = curl_exec($curlObj); | |
$_json = array(); | |
$_json = json_decode($response,true); | |
curl_close($curlObj); | |
return array( | |
'response' => $response | |
,'json' => $_json | |
); | |
}else{ | |
return false; | |
} | |
} | |
} | |
//sample | |
$_url = 'url'; | |
// parameter | |
$_send_param = array( | |
'param1' => 'param1' | |
,'param2' => 'param2' | |
); | |
$_tmp = getCurlPost($_url, $_send_param); | |
$_response = $_tmp['response']; | |
$_json = $_tmp['json']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment