title: Java: how to pass session id for rest api call in api testing?
body: <p>For UI automation testing, I need to do REST Api calls, to get the response. I am passing session id into the HEADER by request.setheader, but I recieved response as :</p>
  
  <pre><code>{"result":{"success":false,"httpCode":200,"errorCode":"INVALID_SESSION_ID","errorMessage":"Session ID not provided... Kindly Login !!"}}
  </code></pre>
  
  <p>I have tried displaying session id and it seems to be fine, What I don't understand is, why it is not been passed to the API. Below is the code:</p>
  
  <pre><code>    HttpClient httpClient = HttpClientBuilder.create().build();
              HttpGet request = new HttpGet(getUrl);
  
              SessionId SessionId = ((FirefoxDriver)driver).getSessionId();
               request.setHeader("Cookie", SessionId.toString());
               HttpResponse response = httpClient.execute(request);
  
                 InputStream ips  = response.getEntity().getContent();
                 BufferedReader buf = new BufferedReader(new InputStreamReader(ips,"UTF-8"));
                 if(response.getStatusLine().getStatusCode()!=HttpStatus.SC_OK)
                 {
                     throw new Exception(response.getStatusLine().getReasonPhrase());
                 }
                 StringBuilder sb = new StringBuilder();
                 String s;
                 while(true )
                 {
                     s = buf.readLine();
                     if(s==null || s.length()==0)
                         break;
                     sb.append(s);
  
                 }
                 buf.close();
                 ips.close();
                 System.out.println("After parsing: "+sb.toString());
  </code></pre>
  
  <p>Output:
  After parsing: strong text</p>
  
  <pre><code>{"result":{"success":false,"httpCode":200,"errorCode":"INVALID_SESSION_ID","errorMessage":"Session ID not provided... Kindly Login !!"}}
  </code></pre>