JAVA HTTPCLIENT

来自 http://stackoverflow.com/questions/1485708/how-do-i-do-a-http-get-in-java

1、

GetMethod get = new GetMethod("http://httpcomponents.apache.org"); // execute method and handle any error responses. ... InputStream in = get.getResponseBodyAsStream(); // Process the data from the input stream. get.releaseConnection();

2、

import java.io.*;
import java.net.*;

public class c {

   public String getHTML(String urlToRead) {
      URL url;
      HttpURLConnection conn;
      BufferedReader rd;
      String line;
      String result = "";
      try {
         url = new URL(urlToRead);
         conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("GET");
         rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         while ((line = rd.readLine()) != null) {
            result += line;
         }
         rd.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return result;
   }

   public static void main(String args[])
   {
     c c = new c();
     System.out.println(c.getHTML(args[0]));
   }
}



3、

urlString = "http://wherever.com/someAction?param1=value1¶m2=value2...."; URL url = new URL(urlString); URLConnection conn = url.openConnection(); InputStream is = conn.getInputStream() 

你可能感兴趣的:(JAVA HTTPCLIENT)