如何用 curl 替换具有 3 个参数的 file_get_contents

我正在尝试在我的网站上配置 google reCAPTCHA v3,并且由于 https,我没有使用 file_get_contents 得到响应。我需要用 curl 替换它,但我不知道如何使用 3 个参数来实现它。


$url="googleverify.com";


$options = array(


        'ssl' => array(

          'verify_peer'=>false,

          'verify_peer_name'=>false,

          'header'  => "Content-type: application/x-www-form-urlencoded\r\n",

          'method'  => 'POST',

          'content' => http_build_query($data)

        )

      );


    $context  = stream_context_create($options);

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


绝地无双
浏览 122回答 2
2回答

素胚勾勒不出你

这修复了错误....$context  = stream_context_create($options);$ch = curl_init();curl_setopt( $ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HTTPHEADER, $options);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );$response = curl_exec($ch);  print_r($response);

万千封印

   'verify_peer'=>false,      'verify_peer_name'=>false,翻译成curl_setopt_array($ch,array(    CURLOPT_SSL_VERIFYPEER=>false,    CURLOPT_SSL_VERIFYHOST=>0,));和      'header'  => "Content-type: application/x-www-form-urlencoded\r\n",翻译成curl_setopt_array($ch,array(    CURLOPT_HTTPHEADER=>array(        "Content-type: application/x-www-form-urlencoded",    )));(并且不,不要将 \r\n 与 CURLOPT_HTTPHEADER 一起使用)和     'method'  => 'POST',翻译成curl_setopt($ch,CURLOPT_POST,true);和  'content' => http_build_query($data)翻译成curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($data));最后,把它们放在一起,我们得到:curl_setopt_array($ch,array(    CURLOPT_SSL_VERIFYPEER=>false,    CURLOPT_SSL_VERIFYHOST=>0,    CURLOPT_HTTPHEADER => array(        "Content-type: application/x-www-form-urlencoded"    ),    CURLOPT_POST=>true,    CURLOPT_POSTFIELDS=>http_build_query($data)));
打开App,查看更多内容
随时随地看视频慕课网APP