title: How to add cookie to url using HttpUrlConnection class in android?
body: <p>I'm trying to parse the json data from an url, when i try to create connection , it throws the exception as 
  <strong>java.net.ProtocolException: cannot write request body after response has been read</strong></p>
  
  <p>I got the response message as <strong>Not found</strong>.</p>
  
  <p>and i checked the url in web browser it shows the Json data when i login wuth my credentials.</p>
  
  <p>so, i found that i need to add the cookie to my connection, but i don't know how to do this.</p>
  
  <pre><code>    public void parseData(String cookie){
      HttpUrlConnection connection;
  
      try{
      URL url = new URL(params[0]);
                      connection = (HttpURLConnection) url.openConnection();
  
                      connection.setRequestProperty("Cookie", cookie);
                      Log.e(TAG, "cookie " + cookie);
  
                      connection.setDoOutput(true);
                      connection.setDoInput(true);
                      connection.setRequestMethod("GET");
  
                      connection.connect();
  Log.e(TAG,connection.getResponseMessage());
  
      /**
      here i'm trying to parse the data 
      using BufferedReader calss
      **/
  
      }
      catch(IOException e){}
      }
  </code></pre>
  
  <p>i need to add the cookie in connection.
  Please help me on this.</p>