B4J Question [SOLVED]Getting Response Header Value of Set-Cookie and Send the Cookies in the Subsequent Request


Active Member
Licensed User
Longtime User
 lang="b4x" title="Current Implementation"]j.PostString("https://apix.com/auth/login/", "username=123456&password=123456")
    j.GetRequest.SetHeader("Content-Type", "application/json")
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
         Log("response "  &  j.GetString)
        cookies = j.Response.GetHeaders.Get("Set-Cookie")
        Log("header vals " & j.Response)

From the response headers, I need to get all the 'Set-Cookie' headers. But I'm not sure how to get the set-cookie value. Any help would be really appreciated.

Also, Once I have got it, I need to use these cookies to send further requests as these are authentication cookies. I'm not sure of that too

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
'You can get all cookies sent to you from server using this:
cookies = j.Response.GetHeaders.Get("Cookie")
'You want to save this variable cookies for further use.

'By default when you send new request to server just pass this variable "Cookie" to the server.

Note: Set-Cookie is response command send to browser to issue Cookie, so if you want to get its value just obtain Cookie variable not Set-Cookie command.
Upvote 0