title: i cant understand the response of an http request
body: <p>why it gives my a 405 error although code is supposed to logically work and the link have a working download
  and I copy some working code from the internet to see what is happening like this topic 
  <a href="https://stackoverflow.com/questions/33576510/how-to-download-an-image-with-a-java-socket-http-1-1-request">How to download an image with a Java socket HTTP/1.1 request?</a>
  and it also doesnt give me a response 200</p>
  
  <p><em>sorry for the messy code iam trying to figure out the problem for about 2 days</em></p>
  
  <pre><code>//package htmlconnection;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedOutputStream;
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.ByteArrayOutputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.net.MalformedURLException;
  import java.net.Socket;
  import java.net.URL;
  import java.net.UnknownHostException;
  import java.nio.charset.StandardCharsets;
  import javax.net.SocketFactory;
  import javax.net.ssl.HttpsURLConnection;
  import javax.net.ssl.SSLSocketFactory;
  public class MyClass {
      public static void main(String args[])throws UnknownHostException, IOException {
          try {
              URL url =new URL("http://www.ncert.nic.in/NCERTS/l/jemh1an.pdf");
              String path=url.getPath();
              String domain=url.getHost();
              System.out.println(path);
              System.out.println(domain);
              Socket socket = new Socket(domain,80);
              PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
              System.out.println(socket.isConnected());
              out.println("Get "+path+" HTTP/1.1\n" +"Host: "+domain);
              out.println();
              out.flush();
              BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
              String inputLine;
              while ((inputLine = in.readLine()) != null &amp;&amp; inputLine.trim() != "0") {
                 System.out.println(inputLine);
              }
          } catch (MalformedURLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  
  //http://www.ncert.nic.in/NCERTS/l/jemh1an.pdf
  //http://www.peoplelikeus.org/piccies/codpaste/codpaste-teachingpack.pdf
  
  </code></pre>
  
  <p>the result is</p>
  
  <pre><code>/NCERTS/l/jemh1an.pdf
  www.ncert.nic.in
  true
  HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  Content-Type: text/html
  Server: Microsoft-IIS/8.5
  X-Powered-By: ASP.NET
  X-Xss-Protection: 1; mode=block
  X-Frame-Options: SAMEORIGIN
  X-Content-Type-Options: nosniff
  Date: Sat, 06 Apr 2019 00:19:13 GMT
  Content-Length: 1293
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/&gt;
  &lt;title&gt;405 - HTTP verb used to access this page is not allowed.&lt;/title&gt;
  &lt;style type="text/css"&gt;
  &lt;!--
  body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
  fieldset{padding:0 15px 10px 15px;} 
  h1{font-size:2.4em;margin:0;color:#FFF;}
  h2{font-size:1.7em;margin:0;color:#CC0000;} 
  h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
  #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
  background-color:#555555;}
  #content{margin:0 0 0 2%;position:relative;}
  .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
  --&gt;
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="header"&gt;&lt;h1&gt;Server Error&lt;/h1&gt;&lt;/div&gt;
  &lt;div id="content"&gt;
   &lt;div class="content-container"&gt;&lt;fieldset&gt;
    &lt;h2&gt;405 - HTTP verb used to access this page is not allowed.&lt;/h2&gt;
    &lt;h3&gt;The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.&lt;/h3&gt;
   &lt;/fieldset&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  Exception in thread "main" java.net.SocketException: Connection reset
      at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
      at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
      at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
      at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
      at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
      at java.base/java.io.InputStreamReader.read(InputStreamReader.java:185)
      at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
      at java.base/java.io.BufferedReader.readLine(BufferedReader.java:326)
      at java.base/java.io.BufferedReader.readLine(BufferedReader.java:392)
      at htmlconnection.Download.main(Download.java:39)
  </code></pre>