在请求标题中添加JsessionID [英] Adding JsessionID in Request Header
本文介绍了在请求标题中添加JsessionID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Jsessionid,我想将它添加到Header,但是我不知道在哪里添加它.
I have got the Jsessionid and I would like to add it to the Header, but I do not know where to add it.
Cookie jSessionID = client.ResponseCookies["JSESSIONID"];
if (jSessionID != null)
{
// JSESSIONID
sessionid = jSessionID.Value;
var settings = new ODataClientSettings()
{
UrlBase = "MyURL"
};
settings.BeforeRequest += delegate(HttpRequestMessage request)
{
String aux = String.Join(":", new String[] {"admin", "admin" });
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(aux);
request.Headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes));
};
var client2 = new ODataClient(settings);
}
推荐答案
以下代码显示了如何向Simple.OData.Client添加其他标头:
The following code shows how to add additional headers to Simple.OData.Client:
var settings = new ODataClientSettings {UrlBase = "http://localhost/odata"};
settings.BeforeRequest += x =>
{
x.Headers.Add("context", "test");
};
var client = new ODataClient(settings);
所以基本上您做对了.有什么不起作用的吗?您可以跟踪HTTP通信并检查是否设置了标头吗?
So basically you're doing it right. Is there anything that doesn't work? Can you trace HTTP communication and check that the header is set?
这篇关于在请求标题中添加JsessionID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文