Httpie: Support for cookies?

Created on 6 Mar 2012  ·  6Comments  ·  Source: httpie/httpie

Is there support for cookies?

The underlying request lib seems to support cookies....

Cheers,

Govinda

question

Most helpful comment

Yes, you can specify cookies just like all the other headers:

$ http GET httpbin.org/cookies Cookie:hello=world
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 06 Mar 2012 13:19:45 GMT
Server: gunicorn/0.13.4
Content-Length: 43
Connection: keep-alive

{
    "cookies": {
        "hello": "world"
    }
}

(See also #13.)

Is that what you mean?

All 6 comments

Yes, you can specify cookies just like all the other headers:

$ http GET httpbin.org/cookies Cookie:hello=world
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 06 Mar 2012 13:19:45 GMT
Server: gunicorn/0.13.4
Content-Length: 43
Connection: keep-alive

{
    "cookies": {
        "hello": "world"
    }
}

(See also #13.)

Is that what you mean?

@jakubroztocil I'm wondering if cookies set by the server can be persisted across calls? Is this possible at all in httpie? So that for example I can use this to test session-based api calls...

@mcnemesis Yes, there is a sessions feature that allows cookies as well as custom headers and auth to persist between requests.

Awesome! Thanks @jakubroztocil

@jakubroztocil Can we use json for setting cookies?
Like {'MOODLEID1_': '%250xxx5C2', 'MoodleSession': 'btsmxxxxxxxosn7'}

@NightMachinary you can use a session file (https://httpie.org/docs#sessions):

Using cookies

$ cat  my-session.json
{
    "cookies": {
        "MOODLEID1_": {
            "value": "%250xxx5C2"
        },
        "MoodleSession": {
            "value": "btsmxxxxxxxosn7"
        }
    },
}
$ http --session ./my-session.json httpbin.org/headers
GET / HTTP/1.1
Cookie: MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7

Using headers

$ cat  my-session.json
{
    "headers": {
        "Cookie": {
            "MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7"
        }
    }
}
$ http --session ./my-session.json httpbin.org/headers
GET / HTTP/1.1
Cookie: MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7
Was this page helpful?
0 / 5 - 0 ratings