【问题标题】:how does HTTP Tunneling work?HTTP隧道如何工作?
【发布时间】:2011-09-06 21:33:17
【问题描述】:

我正在查看 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();

}

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

【问题讨论】:

    标签: tunneling http-tunneling


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-02-10
      • 2010-11-14
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多