常用的curl发包函数

来源:互联网 发布:vs2015中开发php 编辑:程序博客网 时间:2024/05/21 17:40
function curl($url, $postFields = null){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_FAILONERROR, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);if (is_array($postFields) && 0 < count($postFields)){$postBodyString = "";foreach ($postFields as $k => $v){$postBodyString .= "$k=" . urlencode($v) . "&"; }unset($k, $v);curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);   curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));}$reponse = curl_exec($ch);if (curl_errno($ch)){//throw new Exception(curl_error($ch),0);ShowMsg("授权出错,请联系管理员","/");exit();}else{$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);if (200 !== $httpStatusCode){//throw new Exception($reponse,$httpStatusCode);ShowMsg("授权出错,请联系管理员","/");exit();}}curl_close($ch);return $reponse;}

原创粉丝点击