我有Jsessionid,我想将它添加到Header,但我不知道在哪里添加它。
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);
}
答案 0 :(得分:2)
以下代码显示了如何向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通信并检查标头是否已设置?