U
U
Us592020-05-21 11:33:07
PHP
Us59, 2020-05-21 11:33:07

Why does the site not provide the necessary cookies?

I went into inspector mode, made copy as cURL through the site and generated a curl request.

curl_setopt($ch, CURLOPT_URL, 'myURL');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);


I send all Headers. The site answers me with an answer 200, everything seems to be fine, but at the same time in the browser the answer is - Status Code: 304 Not Modified

And now about the problem:
I need to receive cookies from the site.

Here is a photo of what I see in the browser:
5ec63b279acd3441763252.png

The site gives 2 cookies that I need: ak_bmscand akacd_activate_*****_com_phased_release

Now I make a cURL request and I get cookies:
akacd_activate_*****_com_phased_releaseand bm_szand _abck, i.e. the site does not give me cookies that we see in the browser, but gives some others.

Maybe you need to add some settings to cURL?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-05-21
@loonny

The "HTTP 304 Not Modified" client code indicates that it is not necessary to resubmit the requested resources. This is an implicit redirect to a cached resource.
clipping from MDN - 304 Not Modified

Perhaps your server reacts differently to requests from the user (User-Agent) and from a third-party server (Host)

The site gives 2 cookies that I need: ak_bmsc and akacd_activate_*****_com_phased_release
Now I make a cURL request and I get cookies:
akacd_activate_*****_com_phased_release and bm_sz and _abck, i.e. the site does not give me cookies that we see in the browser, but gives some others.

Try passing the User-Agent in the request in addition, like this:
curl_setopt_array($ch, [
    CURLOPT_URL, 'myURL',
    CURLOPT_RETURNTRANSFER, true,
    CURLOPT_FOLLOWLOCATION, true,
    CURLOPT_ENCODING, 'gzip, deflate',
    CURLOPT_COOKIEFILE, $cookiefile,
    CURLOPT_COOKIEJAR, $cookiefile,
    CURLOPT_USERAGENT, '' // Впишите сюда User-Agent из вашего браузера
    ]);

PS why is this ? By default and so GET. PPS Why do CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR have the same file? curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question