PHP curl提交参数到某个网址,然后获取数据

<?php

$data = '你的每个参数';

$url = 'https://www.bz80.vip/'; //举例

$html = post_data($url,$data);

echo $html; //这是是输出的内容

function post_data($url,$data) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_POST, 1);

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POSTFIELDS,  $data);

  curl_setopt($ch, CURLOPT_TIMEOUT, 5);

curl_setopt($ch, CURLOPT_REFERER, 'https://www.bz80.com');

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1');

    curl_setopt($ch, CURLOPT_HTTPHEADER,

        array(

            'Content-Type: application/json; charset=utf-8',

            'Content-Length:' . strlen($data)

    );

    ob_start();

    curl_exec($ch);

    $return_content = ob_get_contents();

    ob_end_clean();

    $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    return $return_content;

}

?>

上一篇:小程序订阅消息【PHP版】


下一篇:解决OracleConnection ORA-1017 和 HRESULT:0x8007000B 错误