Adding JsessionID in Request Header

元气小坏坏 提交于 2019-12-24 14:30:25

问题


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);
     }

回答1:


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

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?



来源:https://stackoverflow.com/questions/29497535/adding-jsessionid-in-request-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!