Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cookies? #26

Closed
Govinda-Fichtner opened this issue Mar 6, 2012 · 9 comments
Closed

Support for cookies? #26

Govinda-Fichtner opened this issue Mar 6, 2012 · 9 comments

Comments

@Govinda-Fichtner
Copy link

Is there support for cookies?

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

Cheers,

Govinda

@jkbrzt
Copy link
Member

jkbrzt commented Mar 6, 2012

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?

@jkbrzt jkbrzt closed this as completed Mar 13, 2012
@mcnemesis
Copy link

@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...

@jkbrzt
Copy link
Member

jkbrzt commented Feb 11, 2015

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

@mcnemesis
Copy link

Awesome! Thanks @jakubroztocil

@NightMachinery
Copy link

NightMachinery commented Apr 19, 2020

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

@jkbrzt
Copy link
Member

jkbrzt commented Apr 19, 2020

@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

@faaizajaz
Copy link

{
    "headers": {
        "Cookie": {
            "MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7"
        }
    }
}

I get an invalid JSON error with the above. it expects a colon and value as it is treating those cookies as a key

@BoboTiG
Copy link
Contributor

BoboTiG commented Sep 16, 2021

@faaizajaz, please open a specific issue.

@faaizajaz
Copy link

@BoboTiG Happy to do so. Just wanted to confirm that if I have a session file containing only the block I shared above, should it work, or am I missing something about how sessions work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants