There is no way out when using cUrl

I am trying to get the contents of a json file here, but when I wanted to echo ($ json), it did not give me any results. I looked at some other issues related to cUrl here in stackoverflow and used the cUrl setting that was given in the answers to make it work fine. Am I doing something wrong? Here is my code:

$url = 'http://steamcommunity.com/profiles/<your 64-bit steam ID>/inventory/json/730/2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$json = json_decode($output, true);
print_r($json);
+4
source share
1 answer

Add this after the line $output = curl_exec($ch);:

$info = curl_getinfo($ch);
echo "<pre>";   
print_r($info);
echo "</pre>";

and type here what you see in the browser, please. Without this information, people cannot help you.

, . HTTP 200, . : " " ( , ).

$info:

Array
(
    [url] => http://steamcommunity.com/profiles//inventory/json/730/2
    [content_type] => text/html; charset=UTF-8
    [http_code] => 200
    [header_size] => 927
    [request_size] => 109
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.561
    [namelookup_time] => 0.062
    [connect_time] => 0.109
    [pretransfer_time] => 0.109
    [size_upload] => 0
    [size_download] => 18266
    [speed_download] => 32559
    [speed_upload] => 0
    [download_content_length] => 18266
    [upload_content_length] => -1
    [starttransfer_time] => 0.561
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 2.17.165.89
    [certinfo] => Array
        (
        )

    [primary_port] => 80
    [local_ip] => 192.168.1.33
    [local_port] => 53366
)    

. , steamcommunity.com? [http_code] => 0, "".

, :

print_r($output);

, , JSON? , $json , .

:

302 HTTP- URL . URL-, JSON. :

$url = 'http://steamcommunity.com/profiles/<your 64-bit steam ID>/inventory/json/730/2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_setopt($ch, CURLOPT_URL, $info["redirect_url"]); // Set new URL
$output = curl_exec($ch); // Go to new URL
$json = json_decode($output, true); // Your JSON here, I checked it
print_r($json); // Print JSON
+2

Source: https://habr.com/ru/post/1625178/


All Articles