HTTP隧道如何工作?

时间:2011-06-02 07:46:15

标签: tunneling http-tunneling

我正在看看JHttpTunnel库,而OutBoundSocket.java中的这段代码让我有些困惑。

 public void connect() throws IOException{
close();

String host=getHost();
int port=getPort();

String request="/index.html?crap=1 HTTP/1.1";

Proxy p=getProxy();
if(p==null){
  socket=new Socket(host, port);
  request="POST "+request;
}
else{
  String phost=p.getHost();
  int pport=p.getPort();
  socket=new Socket(phost, pport);
  request="POST http://"+host+":"+port+request;
}
socket.setTcpNoDelay(true);

in=socket.getInputStream();
out=socket.getOutputStream();
out.write(request.getBytes());
out.write(_rn);
out.write(("Content-Length: "+getContentLength()).getBytes());
out.write(_rn);
out.write("Connection: close".getBytes());
out.write(_rn);
out.write(("Host: "+host+":"+port).getBytes());
out.write(_rn);

out.write(_rn);
out.flush();

sendCount=getContentLength();

}

这似乎直接打开服务器的套接字。防火墙不会阻止它吗?

1 个答案:

答案 0 :(得分:0)

防火墙可以阻止它,但它取决于配置,您可以要求代理不会阻止它,答案也是一样的。 上面的代码只是更大图片的一小部分...... 但通常HTTP隧道应该打开一个到HTTP服务器的套接字,并在HTTP请求上封装一个普通的流,以便在HTTP客户端和HTTP服务器之间发送这些请求套接字,这就是你在这里看到的。 你在这段代码中没有看到的是封装内容。 我希望有所帮助。

相关问题