public static void main(String[ ] args) throws UnknownHostException, IOException
{
String host = "127.0.0.1";
int port = 8080;
Socket socket = new Socket(host, port);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
StringBuffer sb = new StringBuffer();
//请求的连接地址
sb.append("POST /gaga/123.jsp HTTP/1.1\r\n")
.append("Host:"+ host + "\r\n")
.append("Content-Type:application/x-www-form-urlencoded\r\n")
.append("Content-Length:11\r\n") //11 这个数值是看底下内容的长度的 即多少个字符
.append("\r\n")
.append("id=01234567\r\n"); //内容
// System.out.println(sb);
out.write(sb.toString());
out.flush();
//打印响应
String line = "";
while((line = in.readLine()) != null)
System.out.println(line);
{
String host = "127.0.0.1";
int port = 8080;
Socket socket = new Socket(host, port);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
StringBuffer sb = new StringBuffer();
//请求的连接地址
sb.append("POST /gaga/123.jsp HTTP/1.1\r\n")
.append("Host:"+ host + "\r\n")
.append("Content-Type:application/x-www-form-urlencoded\r\n")
.append("Content-Length:11\r\n") //11 这个数值是看底下内容的长度的 即多少个字符
.append("\r\n")
.append("id=01234567\r\n"); //内容
// System.out.println(sb);
out.write(sb.toString());
out.flush();
//打印响应
String line = "";
while((line = in.readLine()) != null)
System.out.println(line);
}
///
1、servlet
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Length: 11
Date: Mon, 16 Jun 2014 14:38:12 GMT
huangliao
2、xxx.jsp
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=79689DEFF39F600F86F6DA27AF9BF767; Path=/gaga/; HttpOnly
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 16
Date: Mon, 16 Jun 2014 14:54:43 GMT
01234567