怎样用JAVA实现模拟HTTP请求,得到服务器的响应时间等参数
1个回答
展开全部
<a href="https://www.baidu.com/s?wd=java.net&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4n1Ddn1ubuHI-Pjc1uycz0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnW0LPHfzPHm4PHczPH0YrjTsr0" target="_blank" class="baidu-highlight">java.net</a>.*;
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);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询