# How to export cookies?

**URL:** <https://community.postman.com/t/how-to-export-cookies/4176>\
**Category:** Help Hub\
**Tags:** cookie\
**Created:** [February 18, 2019, 9:26pm UTC](https://community.postman.com/t/how-to-export-cookies/4176 "2019-02-18T21:26:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bookmoons](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bookmoons/32/1345_2.png) [@bookmoons](https://community.postman.com/u/bookmoons)\
**Post date:** [February 18, 2019, 9:26pm UTC](https://community.postman.com/t/how-to-export-cookies/4176/1 "2019-02-18T21:26:26Z")

</div>

Is there a way to include defined cookies in a collection export? When I try to export it doesn’t include my cookies.

The export:

```
{
	"info": {
		"_postman_id": "77247b9a-2547-4dc8-b502-c9a6448010b0",
		"name": "Cookie",
		"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
	},
	"item": [
		{
			"name": "TestRequest",
			"request": {
				"method": "GET",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": "example.com"
			},
			"response": []
		}
	]
}

```

My defined cookie, for domain [example.com](http://example.com). It does get sent with a test request:

`TestCookie=testval; path=/; domain=.example.com;`

---

<div class="post-metadata">

**Author:** ![Whersh](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@Whersh](https://community.postman.com/u/Whersh)\
**Post date:** [February 20, 2019, 2:40pm UTC](https://community.postman.com/t/how-to-export-cookies/4176/2 "2019-02-20T14:40:08Z")

</div>

I am not an authority on http cookies but I might be bale to shed some light.

First off if you are interested please read the RFC for HTTP cookie [RFC6265](https://tools.ietf.org/html/rfc6265)

- Cookies are generated and distributed by servers.
- Cookies by definition have an expiration date.

Given the above that means that cookies are not good candidates for storing long term. If you were to store them in a collection and come back even a day later they might not be valid and would be regenerated.

What is the reason that you want to store the cookies with the requests?

If you DO want to send specific cookies with a request you would be able to set-cookie via postman in a script [(See documentation)](https://learning.getpostman.com/docs/postman/sending_api_requests/cookies/)

---

<div class="post-metadata">

**Author:** ![georgelai](https://avatars.discourse-cdn.com/v4/letter/g/7993a0/32.png) [@georgelai](https://community.postman.com/u/georgelai)\
**Post date:** [March 10, 2019, 3:05pm UTC](https://community.postman.com/t/how-to-export-cookies/4176/3 "2019-03-10T15:05:38Z")

</div>

On a similar note, is there a way to pass a cookie to the next url?

In Postman, it’s done automatically; when I login, I clearly see the cookie

ASPSESSIONIDCWQCTSBR : ENCJPGFCBCDDLAFEOCPIAJDH

and when I goto the next page to do a search with x-www-form-urlencoded, it works to bring in the body of the html text, in Postman.

However, when I use PHP CURL, there is an error. I can grab the cookie from the login page:  
…  
// execute!  
$response = curl\_exec($ch);

```
// get cookie
// multi-cookie variant contributed by @Combuster in comments
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);
$cookies = array();
foreach($matches[1] as $item) {
    parse_str($item, $cookie);
    $cookies = array_merge($cookies, $cookie);
}
$cookieArr = [];

foreach ($cookies as $key => $value) {
	$cookieArr[$key] = $value;
}

```

but I can’t pass the cookie to the search page:

```
    $ccokie = $cookieKey.'='.$cookieValue; // ASPSESSIONIDCWQCTSBR = ENCJPGFCBCDDLAFEOCPIAJDH
curl_setopt($ch, CURLOPT_COOKIE, $ccokie);

```

It gives me a redirect in the header, like I didn’t enter the proper parameters:

reponse:HTTP/1.1 100 Continue HTTP/1.1 302 **Object moved** Cache-Control: no-cache Pragma: no-cache Content-Length: 130 Content-Type: text/html Expires: Sun, 10 Mar 2019 14:58:49 GMT Location: login.asp Server: Microsoft-IIS/7.0 X-Powered-By: [ASP.NET](http://ASP.NET) Date: Sun, 10 Mar 2019 14:59:48 GMT

It is not a search issue since it would provide an improper search text in the body of the html if that were the case:

```
        <b>There was a problem processing your search request</b>
        <br>You must select at least one account to search.

```

But it just tries to redirect me to the login page again:  
# Object Moved  
This object may be found [here](https://xxxx/login.asp).

Any ideas on how to pass cookies using CURL?

Many thanks,

G
