http请求get post


//https请求(支持GET和POST)
protected function https_request($url, $data = null,$noprocess=false) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
$header = array("Accept-Charset: utf-8");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
//curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); /* * *$header 必须是一个数组** */
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
if($noprocess) return $output;
$errorno = curl_errno($curl);
if ($errorno) {
return array('curl' => false, 'errorno' => $errorno);
} else {
$res = json_decode($output, 1);
if ($res['errcode']) {
return array('errcode' => $res['errcode'], 'errmsg' => $res['errmsg']);
} else {
return $res;
}
}
curl_close($curl);
}

PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
http://blog.csdn.net/liuxinmingcode/article/details/8043150

声明:祁志飞||小祁的博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - http请求get post


QQ:137867590