cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve multiple cookies?

Former Member
0 Kudos
2,340

I have a question similar to "how to retrieve cookies" (http://sqlanywhere-forum.sap.com/questions/5256/how-to-retrieve-cookie-from-web-service) but in my case I have to deal with multiple cookies.

When i try this example, it sort of works, but the cookie is only the last cookie pair in the response. Here's the cookie info it shows in the query result (attribute,value): 'Set-Cookie','BIGServer-8080=123432138.36895.0000; path=/'

But in Mozilla I can inspect the cookie that gets returned, and it has 11 sets of cookies in the Cookie result. (eg, something like this. values have been changed, shortened to protect privacy): LogoURL=www.blah.com; BlahTicket=12341341234123%7C41ee026bc0000000%7C41df3c04d7800000%7C; BlahUser=blaha%7C41ee026bc0000000%7C41df3c04d7800000%7C; BIGServer-8080=123432138.36895.0000;

How can I get all the other cookie pairs? I'm using Sqlanywhere 10.0.1 build 4135. Thanks,

Accepted Solutions (0)

Answers (1)

Answers (1)

MarkCulp
Participant
0 Kudos

Your web request returns the cookie information in its headers. If you look at my answer to the question you will see that the code retrieves the cookie value by looking at the 'set-cookie' header that is returned from the call to the web service. If more than one cookie is being returned then one of two different scenarios can occur:

  • each cookie is being set by using separate set-cookie headers - in this case you need to look at each set-cookie header in the header list (not just the first or last) and extract the information that you need
  • more than one cookie is being set in each set-cookie header - in this case you need to split the attribute value of the set-cookie header at the semicolon (easily done using sa_split_list( attribute, ';' )) and then extract the cookie value out of each piece.

Also please remember that your browser will remember (cache) cookies from one web service call to the next. This can be important to keep in mind if the web service(s) that you are using is(are) setting one cookie per web service call and you are making multiple calls and hence getting multiple cookies - i.e. since your browser caches the cookies you will get the list of all cookies that you have been given during your session (or longer).