[英]HTTPS tunnel inside SSH using JSch
I'd like to communicate with HTTPS server via SSH using Java library JSch. 我想使用Java库JSch通过SSH与HTTPS服务器通信。 Streamforwarding example on library website is easy to use, even on SO is code with that ( Java JSch create channel to access remote server via HTTP(s) ).
图书馆网站上的Streamforwarding示例易于使用,即使在这样的代码上也是如此( Java JSch创建通道以通过HTTP访问远程服务器 )。
Problem is when I want use HttpsURLConnection
class to communicate via HTTPS. 问题是当我想使用
HttpsURLConnection
类通过HTTPS进行通信时。 For instance to make GET
request I try to operate on InputStream
from Channel
class (from JSch) and InputStream
from HttpsUrlConnection
. 例如,使
GET
请求,我尝试在工作InputStream
从Channel
类(从JSch)和InputStream
从HttpsUrlConnection
。
Forward a local port via the SSH connection to the remote HTTP server port: 通过SSH连接将本地端口转发到远程HTTP服务器端口:
Session session = jsch.getSession("username", "ssh.example.com");
// ...
session.connect();
int forwardedPort = session.setPortForwardingL(0, "http.example.com", 80);
Now you can connect HttpsUrlConnection
to http.example.com
and port forwardedPort
. 现在,您可以将
HttpsUrlConnection
连接到http.example.com
并端口forwardedPort
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.