Comments (9)
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.
@mcnemesis Yes, there is a sessions feature that allows cookies as well as custom headers and auth to persist between requests.
from httpie.
@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.
@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.
Awesome! Thanks @jakubroztocil
from httpie.
@jakubroztocil Can we use json for setting cookies?
Like {'MOODLEID1_': '%250xxx5C2', 'MoodleSession': 'btsmxxxxxxxosn7'}
from httpie.
{
"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.
@faaizajaz, please open a specific issue.
from httpie.
@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)
- Trim trailing empty lines from CLI output HOT 1
- Cryptographic API Misuse Vulnerability : Missing SSL Certificate Validation HOT 1
- Filter response keys before print result to the screen
- HTTPie could be lead to believe data was passed in stdin when it was not HOT 1
- httpie -d does not work with gzip compressed content
- Add cli option to generate scriptable or compilable code, or a native executable, that performs the command wherein the option was included
- I got [reports](https://github.com/RageAgainstThePixel/OpenAI-DotNet/issues/236) that this started happening today:
- I got [reports](https://github.com/RageAgainstThePixel/OpenAI-DotNet/issues/236) that this started happening today:
- ## Acceptance Criteria
- it is not possible install for arm linux HOT 3
- Please add support for Mise
- conda-forge lists __win as a MatchSpec dependency for httpie=2.2.0 preventing installation on linux-64 HOT 1
- Failed to use {{key}}={{value}} for nested JSON HOT 1
- Online doc error HOT 3
- Ability to define a custom default user-agent in config.json
- Add .netrc support when using --auth-type bearer
- unable to CONTRIBUTING
- ### Summary
- server HOT 1
- CLI help doesn't show how to launch in a browser!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpie.