首页 > 代码库 > JAVA_HttpURLConnection_客户端接收数据
JAVA_HttpURLConnection_客户端接收数据
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;public class TestMain{ /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { URL url = new URL("http://www.baidu.com"); System.out.println(url.getHost()); HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection(); urlConnection.setConnectTimeout(20000); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); //InputStream in = urlConnection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); System.out.println(in.readLine()); System.out.println(in.readLine()); System.out.println(in.readLine()); urlConnection.disconnect();
} catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
JAVA_HttpURLConnection_客户端接收数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。