---
title: "Socket访问网页"
author: "txazo"
date: "2012-09-01T11:36:35Z"
tags: []
categories: ["编程语言"]
slug: "socket"
draft: false
lastmod: "2012-09-04T19:46:29Z"
id: 1669298
url: "https://txazo.iteye.com/blog/1669298"
---

网页URL：<http://txazo.iteye.com/blog/1669205>
IP地址：118.186.66.50
端口号：80

```java

public class HttpSender {

	private static byte[] request = null;

	static {
		StringBuffer temp = new StringBuffer();
		temp.append("GET http://txazo.iteye.com/blog/1669205 HTTP/1.1\r\n"
            );
        temp.append("Connection: keep-alive\r\n");
		temp.append("Cache-Control: max-age=0\r\n");
		temp.append("\r\n");
		request = temp.toString().getBytes();
	}

	public static void sendHttpRequest() throws Exception {
		Socket socket = new Socket("118.186.66.50", 80);
		OutputStream os = socket.getOutputStream();
		os.write(request);
		os.flush();
		os.close();
		socket.close();
	}

}

```


```java

public class HttpThread implements Runnable {

	@Override
	public void run() {
		try {
			HttpSender.sendHttpRequest();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

```


```java

public class HttpClient {

	public static void main(String[] args) throws Exception {
		for (int j = 0; j < 10; j++) {
			for (int i = 0; i < 20; i++) {
				new Thread(new HttpThread()).start();
				System.out.println(20 * j + i);
			}
			Thread.sleep(1000 * 10);
		}
	}

}

```

这种方法可以快速提升网站的访问量。