+ Reply to Thread
Results 1 to 2 of 2

Thread: Send HTTP request & fetching data using Java

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    24

    Send HTTP request & fetching data using Java

    I am sending a webrequest to page and i want to read the source code of the response , how can i do that ?
    Last edited by cajo; 11-12-2012 at 02:10 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    15
    This is an example on how to fetch any webpage source code and print it.

    Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
     
    public class Main {
        public static void main(String[] args)  {
            try {
                URL url = new URL("http://www.google.com");
                BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                String strTemp = "";
                while(null != (strTemp = br.readLine())){
                System.out.println(strTemp);
            }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts