Here you can find the source of readHttpContent(String domain, String resource, int port)
public static final List<String> readHttpContent(String domain, String resource, int port)
//package com.java2s; /*/*from w w w.ja va 2s . c o m*/ * Copyright 1999-2004 Alibaba.com All right reserved. This software is the confidential and proprietary information of * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with Alibaba.com. */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static final List<String> readHttpContent(String domain, String resource, int port) { Socket socket = null; try { socket = new Socket(domain, port); PrintWriter out = new PrintWriter(socket.getOutputStream()); StringBuilder send = new StringBuilder(); send.append("GET " + resource + " HTTP/1.0").append("\n"); send.append("Accept: text/html").append("\n"); send.append("\n"); out.write(send.toString()); out.flush(); BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); String line = null; List<String> result = new ArrayList<String>(); while ((line = br.readLine()) != null) { if (line.contains("HTTP/1.1 5")) { return Collections.emptyList(); } result.add(line); } return result; } catch (Exception ex) { return Collections.emptyList(); } finally { if (socket != null) { try { socket.close(); } catch (Exception ex) { } } } } }