title: How to programmatically send http request to inner webpage link with java?
body: <p>I am try to making an java application which will be connected with a server and then try to access a link of that server page. For example, I have a link "<a href="http://goodserver.com" rel="nofollow noreferrer">http://goodserver.com</a>" and I am able to connect with this url by this code</p>
  
  <pre><code>InetAddress addr = null;
            Socket sock = new Socket("http://goodserver.com", 80);
            addr = sock.getInetAddress();
            System.out.println("Connected to " + addr);
  </code></pre>
  
  <p>Now I am also able to read the whole source code of this page. But there are button with links. When I go through a browser I can easily click on those button and go to that link. For example a button named "Test" and the corresponding link is "<a href="http://goodserver.com/targets/Test" rel="nofollow noreferrer">http://goodserver.com/targets/Test</a>".</p>
  
  <p>I want to access this link by java but the problem is that it can't be connected directly. I don't want to clcik this link by java as I have read this link "<a href="https://stackoverflow.com/questions/16589417/programmatically-click-a-webpage-button">Programmatically click a webpage button</a>" . I just want to know the mechanism by which a browser can access the link after loading the home page but its not possible through java http request.</p>
  
  <p>I have read the page by this code</p>
  
  <pre><code>URL url = new URL("http://goodserver.com");
    BufferedReader reader = new BufferedReader
    (new InputStreamReader(url.openStream()));
    BufferedWriter writer = new BufferedWriter
    (new FileWriter("data.html"));
    String line;
    while ((line = reader.readLine()) != null) {
       System.out.println(line);
       writer.write(line);
       writer.newLine();
    }
    reader.close();
    writer.close();
  </code></pre>
  
  <p>When replace this home page link with my target button link "<a href="http://goodserver.com/targets/Test" rel="nofollow noreferrer">http://goodserver.com/targets/Test</a>" I am getting the home page source code not the target page.</p>
  
  <p>I know that a browser also send http requests to get pages then it should be possible by java. Thanks in advance.</p>