Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

SetCookie/GetCookie

Can you confirm that GetCookie is working.

C is for Cookie, That's Good Enough For Me
Cookies have long been a valuable tool for maintaining state, implementing authentication, and tracking history with web applications. The SRP HTTP Framework has always supported cookies via the SetResponseHeaderField service (a member of the HTTP_Services module) and the GetResponseHeaderField service (a member of the HTTPClient_Services module). However, a recent project convinced us that Cookies needed a little first-class citizen love. Therefore we have added a few new services so baking and consuming cookies is much yummier:

SetCookie (a member of the HTTP_Services module) - Adds a Set-Cookie header to the response using the indicated Name. The cookie's value and optional attributes will automatically be included as indicated by each argument.
GetCookies (a member of the HTTPClient_Services module) - Returns all cookie strings from the response headers.
GetCookie (a member of the HTTPClient_Services module) - Returns the value for the indicated cookie name.


I see this in Postman after doing Response = HTTP_Services('SetCookie', 'ThisIsACookie','CookieValue')


I then do at the start of my api :
MyCookie = HTTPclient_Services('GetCookie', 'ThisIsACookie') ResponseHeaderFields = HTTPClient_Services('GetResponseHeaderFields') debug

Both values are empty.

Do I need to add 'set-cookie' to additionalvalues in registry (if so, can that be added to the documentation)

Comments

  • Changed the cookie setting to what I may actually need.

    At the END of the api I did- HTTP_Services('SetCookie', 'NextAction','DayList')

    so next call to the api
    MyCookie = HTTPclient_Services('GetCookie', 'NextAction')
    error =Error_Services('GetMessage')

    error = 'Set-Cookie is not a header field in the response.'

    This is in the request headers:


    Also noticed in the postman headers at the top - assume request headers?




    Now I am absolutely totally confused.
  • Just remembered I added HTTP_COOKIE to additionalvalues, so the request header values are a fluke(well in my books anyway)
  • more....

    Cookies=http_services('getRequestHeaderField','Cookie')
    this returns the cookies and their '=' values.
    Which makes sense to me as per a previous discussion, unless I have screwed up again, a 'request' to the server can only get request headers not response headers.
  • OK, this works for me.
    add HTTP_COOKIE to additionalvalues in the registry for OECGI4
    set a cookie and its value using HTTP_Services('SetCookie'

    To get cookies set by the same endpoint I do:

    MyCookies = http_services('getRequestHeaderField','Cookie') convert ';=' to @fm:@vm in mycookies CookieFields =null$ CookieValues =null$ For Each Field in mycookies using @FM CookieFields<-1> =Field<0,1> CookieValues<-1> =Field<0,2> Next Field
  • So you are all good?
  • Unless you want to enlighten me (again) as to where I have gone wrong 🤦‍♂️
  • LOL. No yet at least. I kept trying to catch up with your posts and then you would post something new...so I was having difficulty following your journey and ultimately what you were trying to do. I think you have this handled, but I gave up trying to follow along since it seemed you were always a few steps ahead of me. If you are getting what you want then I think it is fair to say you are all good.
  • Oh, yeah, bad habit…have been pulled up on it before…I post then review,think,test,post!!!!

    Ok, all I want to know is are you happy that HTTP_Services ('SetCookie' and ' HTTPclient_Services('GetCookie', works.
Sign In or Register to comment.