在请求头添加JSESSIONID(Adding JsessionID in Request Head

2019-10-22 13:42发布

我已经得到了JSESSIONID,我想将它添加到页眉,但我不知道在哪里添加。

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

Answer 1:

下面的代码演示如何将其他标题添加到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通信,并检查头设置?



文章来源: Adding JsessionID in Request Header