What is the use and how to use Netscape HTTP Cookie File?

3

I need to save cookies of some accounts that authenticate my APP to Twitter, I searched the web and found something like:?

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

#HttpOnly_.twitter.com  TRUE    /   TRUE    0   _twitter_sess   BAh7DCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCE5GrqRcAToMY3NyZl9p%250AZCIlNDAyMmVkNWY3ZmNiYzdmNGIwZjM5NTZhOTM4ODU1MmM6B2lkIiU1YWJm%250AMWEzYmUxZWM3MmUwYzgzZjZlNzE1MTYwOWU5MjofbG9naW5fdmVyaWZpY2F0%250AaW9uX3VzZXJfaWRsKwdWcHFVOiJsb2dpbl92ZXJpZmljYXRpb25fcmVxdWVz%250AdF9pZCIlSDUyNDduWjdMZThhVVZkY21mWEw1YVVlT0ZaUnNYTHI6CXVzZXJs%250AKwdWcHFV--5148e6c684aadb571a79e48480b6c65398770db9
.twitter.com    TRUE    /   TRUE    1497433103  ct0 b59149399feb3cb9bf073a4f6c8ac99f
.twitter.com    TRUE    /   FALSE   1560483503  guest_id    v1%3A149741150369212010
.twitter.com    TRUE    /   FALSE   1812771541  ads_prefs   "HBERAAA="
#HttpOnly_.twitter.com  TRUE    /   TRUE    1544672341  kdt eyYcfbtxCwHOWoJ2f2cqPC7CozDRWdoddbgMIWnM
.twitter.com    TRUE    /   FALSE   1812771541  remember_checked_on 0
.twitter.com    TRUE    /   TRUE    0   twid    "u=1433497686"
#HttpOnly_.twitter.com  TRUE    /   TRUE    0   auth_token  4faa69fd29e85734f2db445239d0e0d81a6d7afc
twitter.com FALSE   /   FALSE   0   lang    pt

This I found in this domain: link

I would like to know how to do NetScape HTTP Cookie File .

    
asked by anonymous 26.06.2017 / 01:30

1 answer

4

This is a cookie storage format and in this case it was done using cURL, as mentioned in the comments This file was generated by libcurl! Edit at your own risk. .

What is it for?

As a way to store cookies. All the essential information, from which domain, which cookie name, what is the value of the cookie, if it contains the flag , if it contains flag HTTPOnly ... In this situation there is a page that uses Twitter login / password, you send a request to login and then store the cookies, so that in future requests you use these cookies.

Cookies serve a variety of purposes, far beyond login / password. If you know what cookies are and what they are used for and how they work, then you know the reason for storing them.

How do I generate such a file?

This is in the cURL documentation, use:

curl -c /caminho/arquivo.txt https://site.com

This will save cookies from https://site.com to the specified path, to use cookies use -b . More information see the documentation.

In case of PHP use:

$curl = curl_init('https://seusite.com');
curl_setopt($curl, CURLOPT_COOKIEJAR, 'caminho/arquivo.txt');
//...

curl_exec($curl);

This will cause you to save cookies to the specified file. Then, for a future request use these cookies use CURLOPT_COOKIEFILE instead of COOKIEJAR .

The CURLOPT_COOKIEFILE will read the file and send them in the Cookie: header, it supports the old Netscape / Mozilla formats and also a file containing the Set-Cookies: .

>

You have several ways to get / store the cookies on the page, one of the other ways is to simply get the information directly from the header, Set-Cookie: .

    
26.06.2017 / 02:03