日期:2014-05-16 浏览次数:20949 次
/**
* 尝试获取一个domain下的资源,根据http1.0协议尝试读取内容 当然,如果返回的是500系列的异常,那么将不会获取内容
*
* @param domain 域名或ip
* @param resource uri统一资源标记符
* @param port 端口
* @return
*/
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")) {
&nbs