title: Need Java Expert Help on Executing HTTP GET with Cookie
body: <p>My problem is that I want to use Java to implement an application which sends an HTTP GET request to some website. However, the target website needs one cookie to be set:</p>
  
  <p>ShippingCountry=US</p>
  
  <p>If this cookie is not set it returns bad indications. Below are my code segment and I get null from connect().</p>
  
  <pre><code>String urlString = "http://www1.macys.com/catalog/index.ognc?CategoryID=5449&amp;viewall=true";
      try{
      URL url = new URL(urlString);
      URLConnection connection = url.openConnection();
  
      connection.addRequestProperty("Cookie", "ShippingCountry=US");
      connection.connect();
  
      // Create file 
      FileWriter fstream = new FileWriter("d:/out.txt");
      BufferedWriter out = new BufferedWriter(fstream);
      BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      StringBuffer sb = new StringBuffer();
      String line;
      while ((line = rd.readLine()) != null)
      {
          out.write(line);
      }
      rd.close();
      //Close the output stream
      out.close();
  </code></pre>
  
  <p>}</p>
  
  <p>Can somebody help me?</p>