title: Sending a cookie with a POST from a .NET client to a REST API
body: <p>I'm trying to POST a cookie on my .net client api request to a remote server.</p>
  
  <p>Using Fiddler, I can see the cookie I need looks like this:</p>
  
  <p>Request sent 265 bytes of Cookie data:</p>
  
  <pre><code>cookiesDirective=1; __utmt=1; currentLanguage=EN; 
  __utma=198151921.81872271.1398032350.1423043623.1423075781.3; 
  __utmb=198151921.3.10.1423075781; 
  __utmc=198151921; 
  __utmz=198151921.1423043623.2.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
  </code></pre>
  
  <p>However when I POST my api call, my cookie container is empty (according to Fiddler)</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>static async Task RunAsync()
  {
  
      string url = "http://www.myserver.com/Services/GetData";
  
      using (var client = new HttpClient())
      {
          client.BaseAddress = new Uri("http://localhost:9000/");
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
          var model = new Payload() { pageNumber = 2 };
  
          var cookie = new CookieHeaderValue("session-id", "12345");
          cookie.Expires = DateTimeOffset.Now.AddDays(1);
          cookie.Path = "/";
  
          HttpResponseMessage response = new HttpResponseMessage();
  
          response.Headers.AddCookies(new CookieHeaderValue[] { cookie });
  
          response = await client.PostAsJsonAsync(url, model);
          if (response.IsSuccessStatusCode)
          {
               // Testing
          }
  
      }
  }
  </code></pre>