Setting a Cookie

How do you set a cookie for an httpGet()?

I also would love to find out about this. Setting a “Cookie” header does not work.

I can’t even figure out how to set a request header. How do you do that?

First you’d need to capture the value from the “Set-Cookie” header included in the response from an authentication request to the external server in question. You could store that in state, maybe using something like this:

state.cookie = response?.headers?.'Set-Cookie'?.split(";")?.getAt(0)

Then in any subsequent request to this external server, you could use that cookie as follows:

httpGet(uri: 'https://website.com/api/stuff', headers: ['Cookie': state.cookie]) { response ->
  log.debug "Here is the response: ${response.data}"
}

Just as a follow up, I’m all good on cookies.

Thanks!