file_get_contents模拟GET/POST请求

/**

* 发送post请求

* @param string $url 请求地址

* @param array $post_data post键值对数据

* @return string

*/

function send_post($url, $post_data) {

    $postdata = http_build_query($post_data);

    $postdata = json_encode($post_data);

    $options = array(

    'http' => array(

        'method' => 'POST',

        //'header' => 'Content-type:application/x-www-form-urlencoded',

        'header' => 'Content-type:application/json',

        'content' => $postdata,

        'timeout' => 15 * 60 // 超时时间(单位:s)

    ),

   // 跳过https验证

    "ssl" => [

        "verify_peer"=>false,

        "verify_peer_name"=>false,

    ]

  );

    $context = stream_context_create($options);

    $result = file_get_contents($url, false, $context);

    //var_dump($result);return;

    return $result;

function getContent($keyword = null) {

        $send_post = [];

        if (!empty($keyword)){

            $url = 'https://jsonin.com/fenci.php';

  $data = [

  'type' => 'fenci',

  'msg' => '客户提到医院网上负面信息,如何全方位反驳?'

  ];

  //$data = json_encode($data);

            $send_post = send_post($url,$data);

        }

        return $send_post;

    }


getContent();

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。