62,623
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
import java.net.*;
/**
* 捕获服务器
*/
public class CatchServer {
public static void main(String[] args) {
//协议数据
String[] protocol = {
"POST /nav/getsystemconfig.aspx HTTP/1.1",
"User-Agent: IIC2.0/PC 2.2.0230",
"Content-Type: application/x-www-form-urlencode; charset=utf-8",
"Host: nav.fetion.com.cn",
"Content-Length: 75",
"Connection: Keep-Alive"
};
try{
Socket s = new Socket("nav.fetion.com.cn",80);
//发送数据
OutputStream os = s.getOutputStream();
//循环发送
for(int i = 0;i < protocol.length;i++){
os.write((protocol[i] + "\r\n").getBytes());
}
//发送实体数据
os.write("\r\n".getBytes());
//捕获服务器反馈
InputStream is = s.getInputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(is));
String line = br.readLine();
while(line != null){
System.out.println(line);
line = br.readLine();
}
//关闭
br.close();
is.close();
os.close();
s.close();
}catch(Exception e){
e.printStackTrace();
}
}
}