php curl

来源:互联网 发布:淘宝衣服质量好的店铺 编辑:程序博客网 时间:2024/06/05 20:07
public function send_curl($url, $data){    $curl = curl_init();    $header = 'Accept-Charset: utf-8';   //也可以写成一个数组的形式    curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);  // 5.6  6.0 设置不报错    if (stripos($url, "https://") !== FALSE) {  //https不需要证书判断        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);    }    curl_setopt($curl, CURLOPT_URL, $url);    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);    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);    $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);  //关闭curl}
0 0