Anything wrong with my cURL code (http status of 0)?

前端 未结 5 933
半阙折子戏
半阙折子戏 2020-12-30 12:11

Consistently getting a status of 0 even though if I copy and paste the url sent into my browser, I get a json object right back



        
5条回答
  •  囚心锁ツ
    2020-12-30 12:36

    so try this you will get positive results i have added CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to false

    urlencode($co),
                'pa'=>urlencode($pa),
                'par'=>urlencode($par),
                'part'=>urlencode($part),
                'partn'=>urlencode($partn),
                'us'=>urlencode($us)
                );
    
    foreach($fields as $key=>$value) { $fields_string .= $key . '=' . $value . '&' ;}
    
    $fields_string = rtrim($fields_string, "&");
    $fields_string = "?" . $fields_string;
    
    $url = "https://api.xxxxx.com/" . $fields_string;
    
    $request =  $url; 
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT,'3');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
    $content = trim(curl_exec($ch));
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    curl_close($ch);
    print $url;
    print $http_status;
    print $content; 
    
    
    
    ?>
    

提交回复
热议问题