admin管理员组文章数量:1794759
java怎么访问网页
try {
String getURL = "221.182.1.4/apm_internal/sdapi_2/testpj.php";
URL getUrl = new URL(getURL);
// 根据拼凑的URL,打开连接,URL.openConnection()函数会根据 URL的类型,返回不同的URLConnection子类的对象,在这里我们的URL是一个http,因此它实际上返回的是HttpURLConnection
HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
// 建立与服务器的连接,并未发送数据
connection.connect();
// 发送数据到服务器并使用Reader读取返回的数据
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
System.out.println(" ============================= ");
System.out.println(" Contents of get request ");
System.out.println(" ============================= ");
String lines;
while ((lines = reader.readLine()) != null) {
System.out.println(lines);
}
reader.close();
// 断开连接
connection.disconnect();
System.out.println(" ============================= ");
System.out.println(" Contents of get request ends ");
System.out.println(" ============================= ");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "发送消", "消提示", JOptionPane.ERROR_MESSAGE);
return true;
版权声明:本文标题:java怎么访问网页 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686931494a119543.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论