Code Monkey home page Code Monkey logo

Comments (9)

jkbrzt avatar jkbrzt commented on April 28, 2024 6

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?

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024 2

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

from httpie.

jkbrzt avatar jkbrzt commented on April 28, 2024 1

@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

from httpie.

mcnemesis avatar mcnemesis commented on April 28, 2024

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

from httpie.

mcnemesis avatar mcnemesis commented on April 28, 2024

Awesome! Thanks @jakubroztocil

from httpie.

NightMachinery avatar NightMachinery commented on April 28, 2024

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

from httpie.

faaizajaz avatar faaizajaz commented on April 28, 2024
{
    "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

from httpie.

BoboTiG avatar BoboTiG commented on April 28, 2024

@faaizajaz, please open a specific issue.

from httpie.

faaizajaz avatar faaizajaz commented on April 28, 2024

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

from httpie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.