i have been stuck on this issue for days now. i have this json file under 'https://prices.csgotrader.app/latest/prices_v6.json' but when you open the link in the browser, it is prompted to download and not to inspect. So in PHP its unable to inspect the details. I had found a way around this to upload the file on my CPanel and this then allowed me to inspect teh details using the url 'ryzen.me/prices.json'. One problem with this is that the original json is updated on a daily basis and it would not be a viable option for me to download it and upload it manually daily.
How do i turn this url readable for my php to be able to inspect and use the information?
CodePudding user response:
Try using CURL instead..
<?php
$url = "https://prices.csgotrader.app/latest/prices_v6.json";
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "CURL",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10
];
$ch = curl_init ($url);
curl_setopt_array ( $ch, $options );
$return = [];
$return['response'] = curl_exec ( $ch );
$return['errno'] = curl_errno ( $ch );
$return['errmsg'] = curl_error ( $ch );
$return['httpcode'] = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
curl_close ($ch);
if($return['httpcode'] == 200)
{
echo $return['response']; //Here is your response
}
?>
Here is a working example https://paiza.io/projects/e/rMwG3pOC6sRdA89gU885ag