急~~一个socket问题? 在线等
用socket模拟发送HTTP请求 ,想让程序的控制台返回 Http包头 和 html代码
结果运行之后什么反应也没有 怎么回事啊? 急死我了
package com.test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Socket socket;
try {
socket = new Socket("127.0.0.1",8080);
DataInputStream in=new DataInputStream(socket.getInputStream());
DataOutputStream out=new DataOutputStream(socket.getOutputStream());
String request="GET /BBS/ HTTP/1.1/r/n"+
"Accept: */*/r/n"+
"Accept-Language: zh-cn/r/n"+
"Accept-Encoding: gzip, deflate/r/n"+
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR2.0.50727; CIBA)/r/n"+
"Host: localhost:8080/r/n"+
"Connection: Keep-Alive/r/n"+
"Cookie: JSESSIONID=AAD2C453D5FF0D3A6A836F229C4827B5;jforumUserId=2/r/n/r/n/r/n/r/n";
out.writeBytes(request);
String line="";
System.out.println(in.readLine());
while((line=in.readLine())!=null)
{
System.out.println(in.readLine());
}
in.close();
out.close();
socket.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这样一点反应也没有