一个PHP的HTTP POST方法
function RequestPOST($url, $paraArray, $timeout = 0) { $curl = curl_init(); $timeout = $timeout==0?100:$timeout; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //对HTTPS时 不校验证书 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($curl, CURLOPT_POSTFIELDS, $paraArray); curl_setopt($curl, CURLOPT_HTTPHEADER, arry( 'Content-type: text/plain', //传递格式 'Content-length: 100' )); $output = curl_exec($curl); $error = curl_error($curl); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if($code == '200') { // 成功返回 $ret = json_decode($output, true); }else { } return $ret; }
PHP的curl使用方法