duandu1049 2016-05-21 22:35
浏览 58
已采纳

cURL调用不工作没有错误可见(WampServer 3)

I use curl with the Riot API. Everything is working fine on my live server but isn't in local. The curl extension is enabled in WampServer and I don't get any error messages, it's just a blank page.

Here's my code even if it's not actually relevant.

<?php 
    $private_key = "XXX";
    function summoner_name($summoner, $server, $private_key) {
        $summoner_encoded = rawurlencode($summoner);
        $summoner_lower = strtolower($summoner_encoded);
        $curl_url = 'https://' . $server . '.api.pvp.net/api/lol/' . $server . '/v1.4/summoner/by-name/' . $summoner . '?api_key='.$private_key;
        $curl = curl_init($curl_url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }

    function summoner_info_array_name($summoner) {
        $summoner_lower = mb_strtolower($summoner, 'UTF-8');
        $summoner_nospaces = str_replace(' ', '', $summoner_lower);
        return $summoner_nospaces;
    }

    $summoner = "Test";
    $server = "euw";
    $summoner_info = summoner_name($summoner, $server, $private_key);
    $summoner_info_array = json_decode($summoner_info, true);
    $summoner_info_array_name = summoner_info_array_name($summoner);
    $summoner_id = $summoner_info_array[$summoner_info_array_name]['id'];
    $summoner_name_display = $summoner_info_array[$summoner_info_array_name]['name'];
    $summoner_icon = $summoner_info_array[$summoner_info_array_name]['profileIconId'];
    echo '<img src="http://ddragon.leagueoflegends.com/cdn/6.9.1/img/profileicon/'.$summoner_icon.'.png" /><br/><hr>'.$summoner_name_display;
?>   

And here's my phpinfo() for curl extension.
Thanks in advance! enter image description here.

  • 写回答

2条回答 默认 最新

  • douyalin0847 2016-05-21 22:57
    关注

    So, first, as @MaksimVolkob pointed out, and as we discussed in the comments, the first step to resolving these errors is to see what the error message actually is. curl_error() will give you this information.

    Specifically, you're getting an SSL/TLS error:

    SSL certificate problem: unable to get local issuer certificate' (length=63)
    

    If you don't care about security (I do not recommend this for production applications, ever.), you can disable the SSL verification step that is failing:

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    

    The better way is to fix your CA certificate information by setting CURLOPT_CAINFO. This blog post explains this pretty well.

    Edit: As OP discovered, this question has more specifics about getting cURL to recognize the proper CA certificate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。