Home > Back-end >  Using curl to save and display cookies
Using curl to save and display cookies

Time:11-16

for some project I require to activate cookies when sending a curl request and using those cookies later in another call. As an example site lets say I want to call to screenshot from heise.de showing some cookies

I'm assuming those are the cookies, that are generated when connecting to the website.

For testing I now want to do the same with curl and I would expect a similar outcome.

In the Ubuntu console I tried the following


curl -L -c cookie.txt -b cookie.txt www.heise.de

When I open the file I just see:

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.


So, it generates the file, but I don't get, why there are no cookies there. I must be missing something like that those things I saw in the image are not supposed to be there or something.

Some help would be greatly appreciated :)

CodePudding user response:

This was frustrating.
I tried all the tricks in my book that have helped get a response in the past.
It appears to me this site does not want you and your curl or wget.
and they are very good at detecting a curl request.

The problem is this URL does not return cookies in the header when the request is made with curl. With some request headers I have tried, there is no response at all.

Here are the response headers when I curled https://www.heise.de/

HTTP/2 200 
server: nginx 
date: Tue, 08 Nov 2022 22:58:40 GMT 
content-type: text/html; charset=UTF-8 
last-modified: Tue, 08 Nov 2022 22:58:40 GMT 
age: 18 
accept-ranges: bytes 
strict-transport-security: max-age=15768000 
x-frame-options: DENY 
x-xss-protection: 1; mode=block 
x-content-type-options: nosniff 
x-hacc-refreshed: 
vary: Accept-Encoding, X-Export-Format, X-Export-Agent, X-Export-IAP 
cache-control: no-store 
content-length: 756164 

My wget:

wget -SO- -T 5 -t 1 https://www.heise.de/ > test.html

Response:

--2022-11-08 18:46:53--  https://www.heise.de/
Resolving www.heise.de (www.heise.de)... 2a02:2e0:3fe:1001:7777:772e:2:85, 193.99.144.85
Connecting to www.heise.de (www.heise.de)|2a02:2e0:3fe:1001:7777:772e:2:85|:443... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Server: nginx
  Date: Tue, 08 Nov 2022 23:46:38 GMT
  Content-Type: text/html; charset=UTF-8
  Last-Modified: Tue, 08 Nov 2022 23:46:38 GMT
  Age: 16
  Accept-Ranges: bytes
  Strict-Transport-Security: max-age=15768000
  x-frame-options: DENY
  X-XSS-Protection: 1; mode=block
  X-Content-Type-Options: nosniff
  X-Hacc-Refreshed:
  Vary: Accept-Encoding, X-Export-Format, X-Export-Agent, X-Export-IAP
  Cache-Control: no-store
  Content-Length: 757423
  Connection: keep-alive
Length: 757423 (740K) [text/html]
  • Related