[英]How to send multiple cookies to Java WebServices from WCF Client
I need to send multiple set of cookies like below to Java WebService from WCF Client. 我需要从WCF客户端向Java WebService发送多组如下所示的Cookie。
Set-Cookie: JSESSIONID=ABCDLhSgAceJ9bpEFSgLvi53; Set-Cookie:JSESSIONID = ABCDLhSgAceJ9bpEFSgLvi53; Path=/XXX
路径= / XXX
Set-Cookie: zz=mmm;kk=qqq;XXXX; Set-Cookie:zz = mmm; kk = qqq; XXXX;
These two cookies I am receving from login JAVA WebService and I need to forward these same cookies to other Java Web Service for maintaining sessions. 我从登录JAVA WebService中获取了这两个cookie,我需要将这些cookie转发给其他Java Web Service来维护会话。 I have tried with following using IClientMessageInspector but could not sent exact two cookie as shown above.
我已经尝试使用IClientMessageInspector进行以下跟踪,但是无法正确发送两个cookie,如上所示。 I can send only one.
我只能寄一个。
if (!string.IsNullOrEmpty(cookieValueFromLogin))
{
string[] cookieValues = cookieValueFromLogin.Split(new char[] { ',' });
for (int i = 0; i < cookieValues.Length; i++)
{
if (!string.IsNullOrEmpty(cookieValues[i]))
{
httpRequestMessage.Headers.Add("Cookie", cookieValues[i] );
}
}
}
Please help here if anybody knows. 如果有人知道,请在这里帮助。
Thanks MP 谢谢议员
You only actually need to set one header key: Cookie. 您实际上只需要设置一个标题键:Cookie。 The request cookie header will look like:
请求Cookie标头将如下所示:
Cookie: JSESSIONID=ABCDLhSgAceJ9bpEFSgLvi53;zz=mmm;kk=qqq; Cookie:JSESSIONID = ABCDLhSgAceJ9bpEFSgLvi53; zz = mmm; kk = qqq;
The modification below should generate the correct value, though it can almost certainly be implemented much more cleanly. 尽管几乎可以肯定地将其更清晰地实现,但下面的修改应生成正确的值。
if (!string.IsNullOrEmpty(cookieValueFromLogin))
{
string[] cookieValues = cookieValueFromLogin.Split(new char[] { ',' });
string cookieHeader = new string();
for (int i = 0; i < cookieValues.Length; i++)
{
if (!string.IsNullOrEmpty(cookieValues[i]))
{
cookieHeader = cookieHeader + cookieValues[i];
}
}
httpRequestMessage.Headers.Add("Cookie", cookieHeader );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.