简体   繁体   English

cURL与PHP-HTTP cURL到HTTPS

[英]cURL with PHP - HTTP cURL to HTTPS

I have the following bit of PHP, it works locally (via apache and localhost) but not on my hosting - $response is always empty: 我有以下PHP, 可在本地工作(通过apache和localhost),但不能在我的主机上使用- $response始终为空:

function get_data($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }

    $api_key = 'my_api_key'; 

    $randomString = generateRandomString(10);
    $endLabel = sha1(md5($randomString));
    $user_id = $endLabel;

    $amount_doge = '5'; 

    $url = "https://dogeapi.com/wow/?api_key=".$api_key."&a=get_new_address&address_label=".$user_id;
    $response = get_data($url);

I wondered if this could be because I'm hosted on HTTP (no SSL option) and I'm calling a HTTPS domain? 我想知道是否可能是因为我托管在HTTP(无SSL选项)上,并且正在调用HTTPS域? If so, is there a way around this? 如果是这样,是否有办法解决? I've tried curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 我试过curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); but it doesn't seem to do anything :( 但它似乎无能为力:(

try to use echo curl_error($ch) after $data = curl_exec($ch); 尝试在$data = curl_exec($ch);之后使用echo curl_error($ch) $data = curl_exec($ch); to see what curl says it wil lreport you what happened 看看卷曲的意思会告诉你发生了什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM