Note that there are some explanatory texts on larger screens.

plurals
  1. POManually sending GET request to a website. 302 redirect error
    text
    copied!<p>I am currently working on a web scraper using java. I am manually sending the GET request by setting up a tcp connection and using printerwriter. </p> <p>I am able to connect to most websites such as yahoo.com or cracked.com and receive a response, BUT I am unable to connect to my target website - vinylengine.com. It will always return a 302 error.</p> <p>I have compared my send request with my browser's and they are nearly identical.</p> <p><strong>My header:</strong></p> <pre><code>GET / HTTP/1.1 Host: www.vinylengine.com </code></pre> <p><strong>My Response:</strong></p> <pre><code>HTTP/1.1 302 Found Date: Thu, 06 Jun 2013 19:27:00 GMT Server: Apache Location: http://www.nakedresource.com/ Cache-Control: max-age=1209600 Expires: Thu, 20 Jun 2013 19:27:00 GMT Content-Length: 213 Content-Type: text/html; charset=iso-8859-1 &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt; &lt;html&gt;&lt;head&gt; &lt;title&gt;302 Found&lt;/title&gt; &lt;/head&gt;&lt;body&gt; &lt;h1&gt;Found&lt;/h1&gt; &lt;p&gt;The document has moved &lt;a href="http://www.nakedresource.com/"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p><strong>Browser's header:</strong></p> <pre><code>GET http://www.vinylengine.com/ HTTP/1.1 Host: www.vinylengine.com User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Cookie: __utma=72407316.18415374.1370488314.1370497873.1370543389.3; __utmz=72407316.1370488314.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); SESSaf8d12283bdbdc5f5bbfb2aef054db6d=1f0676e5cab0ba2c5a80e76ea0bd6f75; __utmc=72407316; has_js=1; __utmb=72407316 Connection: keep-alive If-Modified-Since: Thu, 06 Jun 2013 18:02:53 GMT If-None-Match: "2186d59ac297e0f1a43433fa61e8a94b" </code></pre> <p><strong>Code:</strong></p> <pre><code>public void sendRequest(String extensionString, String urlString) { try { //BufferedReader inFromServer; //PrintWriter outToServer; //These 2 are initalized elsewhere outToServer.println("GET " + extensionString + " HTTP/1.1"); outToServer.println("Host: " + urlString); outToServer.println(""); outToServer.flush(); String temp; while((temp=inFromServer.readLine()) != null) { System.out.println(temp); } return; } catch (Exception e) { System.out.printf("sendRequest failed: %s",e); return; } } </code></pre> <p><strong>I have tried changing the host name to nakedresource.com, but when I do that, I get the page source for nakedresource.com and not vinylengine.com</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload