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

Cookies don't seem to be persisting across requests #107

Closed
sbrl opened this issue Sep 21, 2015 · 8 comments
Closed

Cookies don't seem to be persisting across requests #107

sbrl opened this issue Sep 21, 2015 · 8 comments

Comments

@sbrl
Copy link

sbrl commented Sep 21, 2015

Does got support cookies? If so, how do I pass it a cookie jar? Where do I get a cookie jar? The README doesn't seem to explain this.

Context: I'm switching a project of mine from request to got, which uses a cookie jar (it doesn't appear to work without one). When I finished switching it over, I got a "Not Authorised" response from a url in a sequence of 3 which I should have got a success response instead. This leads me to think that got isn't storing cookies correctly.

@sbrl sbrl changed the title Cookies Cookies don't seem to be persisting across requests Sep 21, 2015
@floatdrop
Copy link
Contributor

@sbrl got does not have cookie support out-of-the-box, but it can be easly achieved with cookie module:

let got = require('got');
let cookie = require('cookie');

got('google.com', {
    headers: {
        cookie: cookie.serialize('foo', 'bar')
    }
});

See also:

@sbrl
Copy link
Author

sbrl commented Sep 21, 2015

Ok, Thanks! I was hoping that there would be built in support. I'll see what I can do. The problem is that I need to make multiple different requests and save the cookie state after each one in order to login to a particular online service :/

@floatdrop
Copy link
Contributor

@sbrl I'd recommend make all requests to this service through new module (like gh-got or vk-got) and add default jar storage into it.

@sbrl
Copy link
Author

sbrl commented Sep 21, 2015

Default jar storage? What's that?

@floatdrop
Copy link
Contributor

@sbrl shared instance of tough-cookie for example.

@sbrl
Copy link
Author

sbrl commented Sep 21, 2015

@floatdrop Right. I don't understand how I can pass a default jar into a gh-got or vk-got instance without doing it manually - in which case I should use vanilla got instead. Sorry for all the questions :(

@FranklinYu
Copy link

Bloated request has built-in cookie jar support.

@gajus
Copy link
Contributor

gajus commented Jul 30, 2018

This thread doesn't answer the question how to use tough-cookie with got, e.g. How will the redirects be handled?

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

4 participants