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

2021/8/1 17:36:07

本文主要是介绍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 curl提交参数到某个网址,然后获取数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程