2

Related to How can I replicate this cookie functionality on my Web Client?

I discovered in a previous question that I need to set a cookie in my request header.

I call a login method on a 3rd party web service, this returns a cookie that I need to use on subsequent requests to that server. I had assumed that the browser keeps this cookie and attaches it to the appropriate request, however, this does not seem to be the case (I can see it isn't in firebug).

How can I set the cookie on my request header?

My call is as follows:

var call = serviceUriString + '?' + strRequest;
$.post(call, function(d) {}, 'text').success(function(d) { ..//do something

I think I may have to use jQuery.ajax( url [, settings] ) beforesend, but I can't find any good examples of how to set the cookie, or indeed how to get it out / persist it from the response from the previous login request (so that I can then attach it).

As @edr points out, I am doing this client side. So my website calls a web service in client side code.

Community
  • 1
  • 1
Mr Shoubs
  • 14,629
  • 17
  • 68
  • 107
  • 1
    Probably worth mentioning that you're doing all this client-side. – edralph May 01 '12 at 16:57
  • This post might help http://stackoverflow.com/questions/1041285/does-jquery-send-cookies-in-a-post – Seshagiri May 01 '12 at 17:00
  • @Seshagiri I've come across this a number of times, but I can't work out how to apply it to my jQuery. It mentions .net and php, but not client side scripting. – Mr Shoubs May 01 '12 at 17:03

2 Answers2

1

I'm not sure if there is an answer to this, however I can add ;jsessionid=[value_here]? to my url and that works.

For example:

var call = serviceUriString + ';jsessionid=' + [value_here] + '?' + strRequest;
$.post(call, function(d) {}, 'text').success(function(d) { ..//do something

similar answer is here: https://stackoverflow.com/a/10353875

Community
  • 1
  • 1
Mr Shoubs
  • 14,629
  • 17
  • 68
  • 107
0

Just speculating here:

Since cookies go along for the ride when doing ajax calls I suspect that the cookie created is for the 3rd party domain so it stand to reason that you will not find it in the cookies for your domain.

Try adding the cookie in client code before doing the post. This SO question may help:

How do I set/unset cookie with jQuery?

Community
  • 1
  • 1
Eben Roux
  • 12,983
  • 2
  • 27
  • 48