duanfu3634 2017-08-02 04:54
浏览 132

PHP - 使用HTTPS的CURL [关闭]

I'm trying to get Json Data from a https url.

I have tested and working code to do just this for http... but I am yet to find a working version for https. This needs to be secure code, not quick fixes please...

This is my http version that works

<?php
$key = "admin"; //user
$secret = "admin"; //pass
$api_ep = "http://$Hostname:$Port/$address";


if ($key && $secret){
$curl_opts = array(
  CURLOPT_HTTPHEADER=>array("Accept: application/json"),
  CURLOPT_VERBOSE=>false,
  CURLOPT_HEADER=>false,
  CURLOPT_POST=>false,
  CURLOPT_RETURNTRANSFER=>true,
  CURLOPT_HTTPAUTH=>CURLAUTH_DIGEST,
  CURLOPT_USERPWD=>$key.":".$secret,
  CURLOPT_URL=> $api_ep  
);
}

function disp($opts,$var){
  $ch = curl_init();

  curl_setopt_array($ch, $opts);
  $raw_resp = curl_exec($ch);
//  $array_resp = json_decode($raw_resp);

  //print_r($array_resp);
  print_r($raw_resp);
  curl_close($ch);
//$array = json_decode($raw_resp, true);
//print_r($array_resp);
//disp_table($array_resp, $var);
}

disp($curl_opts,$Type);
?>

Thanks in advanced!

  • 写回答

3条回答 默认 最新

  • douqiao5314 2017-08-02 05:03
    关注

    Add the following to disable SSL verification.

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    

    Curl SSL fails to verify self signed certificates and hence, you will not be able to connect with https hosts if they are using self signed certificates.

    function disp($opts,$var){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt_array($ch, $opts);
      $raw_resp = curl_exec($ch);
      print_r($raw_resp);
      curl_close($ch);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题