0

I am having some trouble with the CURL command line. I am trying to send a POST request to an API, which starts a new session. Now, I would like to be in the same session when I make the next request, however when I make another CURL request, it gives me a completely different session.

For example, I make the following request to a server:

curl -v --keepalive --data "username=username&password=password" http://example.com/login

The command above gives me a unique session id of something like

prgl4esck2hu7ge1gustnfgb35

Then I put in another request to a server:

curl -v --keepalive http://example.com/checkLogin

And when I put in the command above into CMD, it gives me a completely different session id. In other words, the session is not persistent and I need it to be persistent. I have no idea what I am doing wrong. Please help, I have been trying to figure this out for hours now. Any help is greatly appreciated!

BTW: This works perfectly fine in Postman, so I know it has to be a problem with the curl request from the command line.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
camrymps
  • 327
  • 3
  • 11

1 Answers1

1

I presume that when you say a "new session", you mean you get a new set of cookies?

You probably want to record the received cookies and then send the appropriate ones back in subsequent calls. I've detailed this in an earlier answer on how to send cookies with curl.

--keepalive is something different: it asks for TCP keep-alive to be enabled for the connection (which it already does by default).

Community
  • 1
  • 1
Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222