首頁  >  文章  >  後端開發  >  PHP Curl 函数,支持POST GET_PHP教程

PHP Curl 函数,支持POST GET_PHP教程

WBOY
WBOY原創
2016-07-13 10:19:52878瀏覽

PHP Curl 函数,支持POST GET

/**
 * @author       default7<default7@zbphp.com>
&#160;* @param        $url
 * @param string $method
 * @param array  $postData
 *
 * @return mixed|null|string
 */
function getHttpContent($url, $method = &#39;GET&#39;, $postData = array())
{
    $data = &#39;&#39;;

    if (!empty($url)) {
        try {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30); //30秒超时
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            //curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
            if (strtoupper($method) == &#39;POST&#39;) {
                $curlPost = http_build_query($postData);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
            }
            $data = curl_exec($ch);
            curl_close($ch);
        } catch (Exception $e) {
            $data = null;
        }
    }

    return $data;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/871188.htmlTechArticlePHP Curl 函数,支持POST GET /** * @author default7 * @param $url * @param string $method * @param array $postData * * @return mixed|null|string */function getHttpContent($url,...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn