Recently the author of the project needs Java to simulate HTTP requests, get DNS resolution TCP connections and other detailed time-consuming information.
The urlconnection provided in the Java API and the httpclient provided by Apache are not up to this requirement, and two development is too time consuming. So Google's.
Finally, two solutions are obtained:
One is to use http4j.
The Open source project uses the socket method, simulates the request, records the timestamp, and basically satisfies the requirement. For the header customization and other details, on this basis can be more convenient two times development. Only some of these bugs need to be fixed, such as when HTTPS links are not getting SSL time. The risk of using the project is instability and controllability.
Http4j code after a minor change.
http://download.csdn.net/detail/zhongyuan_1990/8837281
The second is to use curl.
Google's, curl itself has no support for Java, and a third provides a binding to use curl. May be the author's limited ability to successfully compile it in Windows. Google also did not find resources to download the relevant javacurl.dll. Finally had to give up. Select Use the command line mode to manipulate curl.
Java using the Curl command demo
Package Com.netbirdtech.libcurl.test;import Java.io.bufferedreader;import Java.io.ioexception;import Java.io.inputstreamreader;public class Test {public static void main (string[] args) {String []CMDS = {"Curl", "-I", "-w", "Status%{http_code};dns Time%{time_namelookup};" + "Wait Time%{time_pretransfer}tcp connection%{time_connect}; Make request%{time_ Starttransfer}; "+" Total Time%{time_total} "," http://www.baidu.com "}; Processbuilder pb=new Processbuilder (CMDS);p B.redirecterrorstream (true); Process p;try {p = Pb.start (); BufferedReader Br=null; String line=null;br=new BufferedReader (New InputStreamReader (P.getinputstream ())); while ((Line=br.readline ())! = NULL) {System.out.println ("\ t" +line);} Br.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}
About the Curl Java analog HTTP request