分享

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

 董小宝的日常 2021-07-12

<?php

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

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

$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.');

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;

}

?>

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约