I'm trying to get a json result from a website to analyze in my system.
In the first request of the day I receive Status 200 OK
I get the result that I'm expecting.
But if I try to get the result again making a refresh in the page for example, I receive the following error
"close Cache-Control: no-cache Pragma: no-cache "
With the following HTTP HEADER
"HTTP/1.1 302 Found : Moved Temporarily Location: http://localhost Cache-Control: private, no-cache, max-age=0, no-store, must-revalidate Expires: Thu, 01 Jan 1970 00:00:01 +0000 Pragma: no-cache
For some reason the server returns error 302 and move to localhost and I have to wait until the next day to get the result 200 again.
Running var_dump(curl_error($curl));
. I get bool(false)
My code
<?php $cookie="files/cookies.txt";
$url = "https://extra.bet365.com/ResultsApi/GetResults?sportName=sport&sportId=146&fixtureId=104716787&competitionId=20700663&fromDate=2021-07-01T04:05:00&toDate=2021-07-01T04:05:00&challengeId=62233643&marketOverride=";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($curl, CURLOPT_COOKIEFILE, $cookie);
$headers = array(
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:89.0) Gecko/20100101 Firefox/89.0",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
"Connection: keep-alive",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp); ?>
My Answer:
It seems like the website you are trying to access is redirecting you to localhost after the second request. This could be due to various reasons such as server-side restrictions or security measures.
One thing you can try is to clear your cookies before making the second request. You can do this by adding the following line before making the request:
php
unlink($cookie);
This will delete the cookie file before making the request, which might help in avoiding the redirection to localhost.
Additionally, you can try adding the following option to your cURL request to follow the redirection:
php
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
This will instruct cURL to follow any redirections automatically, which might help in avoiding the redirection to localhost.
If the issue persists, you may need to investigate further by checking the server-side settings of the website you are trying to access or contacting the website administrator for more information on why the redirection is happening.
Rate this post
4 of 5 based on 7426 votesComments