如何附加一个cookie到我的jQuery post请求头? [英] How can I attach a cookie to my jQuery post request header?

查看:3744
本文介绍了如何附加一个cookie到我的jQuery post请求头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关于如何在我的Web客户端上复制此Cookie功能?

我在上一个问题中发现我需要在请求头中设置一个cookie。

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

我在第三方Web服务上调用登录方法,这会返回一个cookie,我需要在对该服务器的后续请求时使用。我假设浏览器保留这个cookie并附加到适当的请求,但是,似乎不是这样(我可以看到它不是在firebug)。

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).

如何在我的请求标头上设置Cookie?

How can I set the cookie on my request header?

我的通话如下:

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

我想我可能需要使用 jQuery.ajax (url [,settings]) beforesend,但我找不到任何好的例子如何设置cookie,或者实际上如何从上一次登录请求的响应中获取/持久化(因此

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).

正如@edr指出的,我正在做这个客户端,所以我的网站在客户端代码中调用一个web服务。

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

推荐答案

我不确定是否有答案,但我可以添加; jsessionid = [value_here ]?到我的网址。

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

例如:

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

类似的答案在这里: http://stackoverflow.com/a/10353875

这篇关于如何附加一个cookie到我的jQuery post请求头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆