怎样用JAVA实现模拟HTTP请求,得到服务器的响应时间等参数
发布网友
发布时间:2022-04-25 13:09
我来回答
共1个回答
热心网友
时间:2022-04-18 08:26
java.net.*;
public class HttpDemo{
public static void main(String[] args)throws Exception{
URL url = new URL('地址');
HttpURLConnection http = (HttpURLConnection)url.openConnection();
//获取网页的源码
BufferedReader br = new BufferedReader(new InputStreamReader(http.getInputStream()));
String line = "";
while((line=br.readLine())!=null){
System.out.println(line);
}
br.close();
//获取参数:
String value = getRequestProperty(String key);
}
}