1

I am trying to use ServiceStacks Http Utils, but for some reason I can't seem to be able to set the JSession cookie I received from logging in via basic auth. This is what I've tried so far...

response = imiLogin.PostToUrl("", requestFilter: req => {req.Headers["Cookie"] = sessionCookie.message;}).FromJson();

Any help would be appreciated.

Josh Ames
  • 46
  • 4

1 Answers1

0

ServiceStack's HTTP Utils is a wrapper around .NET's HttpWebRequest where you would use the HttpWebRequest.CookieContainer to set cookies, e.g:

url.PostJsonToUrl(body, requestFilter: req =>
        req.CookieContainer.Add(new Cookie("name", "value", "/")))
    .FromJson<Response>();
mythz
  • 141,670
  • 29
  • 246
  • 390
  • What is the recommended way to add a cookie via HttpUtils now that the request filter is using HttpRequestMessage rather than HttpWebRequest? – PlantPorridge Apr 13 '22 at 13:16
  • 1
    Can't be done on the request, you'll need to [configure the HttpClient](https://docs.servicestack.net/http-utils#connect-to-httpfactory) to [include cookies](https://stackoverflow.com/q/12373738/85785). – mythz Apr 13 '22 at 13:54