title: How to send the authentication cookie WebRequest and receive the response in JIRA through REST api?
body: <p>all</p>
  
  <p>I am working on JIRA, i am sending the authentication request from saparate code and i am getting the response, later i need to fetch all issues from the JIRA than i am sending the request that time i am getting the 401 (Unauthorized) while i am sending the same username and password with gZip compression.
  my first request code is following where from i am getting the proper response as authenticated.</p>
  
  <pre><code>string urll = ConfigurationManager.AppSettings["globalUrlForLP"];
  HttpWebRequest request;
  WebResponse response;
  String uri;
  LpResponse lp_response;
  uri = urll + url;
  request = WebRequest.Create(uri) as HttpWebRequest;
  request.Credentials = CredentialCache.DefaultCredentials;
  request.Method = verb;
  request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
  request.Headers.Set("Authorization", Convert.ToBase64String(Encoding.ASCII.GetBytes(this.Username + ":" + this._password)));
  
  if (null != data)
  {
      request.ContentType = "application/json";
      String jsonPayload = JsonConvert.SerializeObject(data);
      byte[] jsonPayloadByteArray = Encoding.ASCII.GetBytes(jsonPayload.ToCharArray());
      request.GetRequestStream().Write(jsonPayloadByteArray, 0, jsonPayloadByteArray.Length);
  }
  lp_response = new LpResponse();
  try
  {
       response = request.GetResponse();
       StreamReader reader = new StreamReader(response.GetResponseStream());
       lp_response.response = reader.ReadToEnd();
  }
  catch (Exception e)
  {
       lp_response.error = e;
  }
  return lp_response;
  }
  </code></pre>
  
  <p>from it i am getting response as following.</p>
  
  <pre><code>{
    "session": {
    "name": "JSESSIONID",
    "value": "12345678901234567890"
    },
      "loginInfo": {
      "failedLoginCount": 10,
      "loginCount": 127,
      "lastFailedLoginTime": "2014-10-28T06:52:52.211+0000",
      "previousLoginTime": "2014-10-28T06:52:52.211+0000"
       }
  }
  </code></pre>
  
  <p>Now come to the point, I want to get all projects from the JIRA for that i written following code and i am getting here 401 Unathorized. After getting this i read the JIRA REST Api documentation and there i found following. </p>
  
  <p><strong>"Returns information about the caller's session if the caller is authenticated.
  Note that the response contains the Set-Cookie HTTP headers that must be honoured by the caller. If you are using a cookie-aware
  HTTP client then it will handle all Set-Cookie headers automatically. This is important because setting the JSESSIONID cookie alone may
  not be sufficient for the authentication to work."</strong></p>
  
  <p>so please suggest me what i need to do more with following code ?</p>
  
  <p><strong>my Failure code is following.</strong></p>
  
  <pre><code>string url = ConfigurationManager.AppSettings["urlAllJiraProject"];
  LpResponse res = new LpResponse();
  HttpWebRequest request;
  WebResponse response;
  List&lt;AllJiraProject&gt; jiraproject = new List&lt;AllJiraProject&gt;();
  request = WebRequest.Create(url) as HttpWebRequest;
  request.Credentials = CredentialCache.DefaultCredentials;
  request.Method = "GET";
  request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
  request.Headers.Set("Authorization", Convert.ToBase64String(Encoding.ASCII.GetBytes(userNamejira + ":" + passwordjira)));
  LpResponse lp_response = new LpResponse();
  try
  {
      response = request.GetResponse();
      StreamReader reader = new StreamReader(response.GetResponseStream());
      lp_response.response = reader.ReadToEnd();
      jiraproject = (List&lt;AllJiraProject&gt;)JsonConvert.DeserializeObject&lt;List&lt;AllJiraProject&gt;&gt;(lp_response.response.ToString());
  }
  catch (Exception e)
  {
      lp_response.error = e;
  }
  return jiraproject;
  </code></pre>