0

我用这个库创建 SSH 隧道:https ://sshnet.codeplex.com/

隧道工作正常,如果在 Firefox 中输入 url,如:http://localhost:10000/somefile.js

它总是被退回。但是,如果我在输出中第一次请求出现后从控制台应用程序请求它

SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.

之后

'SSH_MSG_CHANNEL_EOF:#0'。

代码卡在这里:

response = request.GetResponse();

然后超时。

这是我的完整代码:

        connectionInfo = new PrivateKeyConnectionInfo(domain, name, new PrivateKeyFile(File.OpenRead(keyPath), pass));
          using (client = new SshClient(connectionInfo)) {
            client.ErrorOccurred += client_ErrorOccurred;
            client.Connect();
            port = new ForwardedPortLocal(boundHost, boundPort, remoteHost, remotePort);           
            client.AddForwardedPort(port);
            port.Exception += port_Exception;
            port.Start();

            //This request successfully returned but after this output shows SSH_MSG_CHANNEL_EOF
            SendRequest();
            Thread.Sleep(2000);

            // And in this Request is code stacked on get response
            SendRequest();

        // Request Call 
        void SendRequest(){
        string url = "http://localhost:10000/somefile.js";
        WebResponse response = null;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentType = "application/json";
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0";
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.KeepAlive = true;
        request.Timeout = 15000;

        // Here its stacked after 2 request

        response = request.GetResponse();

        MemoryStream stream = new MemoryStream();
        response.GetResponseStream().CopyTo(stream);
        stream.Position = 0;
        StreamReader reader = new StreamReader(stream);
        string bssResponse = reader.ReadToEnd();
        Console.WriteLine(bssResponse.Substring(0, 20));

那么来自 Firefox 和来自控制台应用程序的调用之间可能有什么区别?

来自 firefox 的请求调用隧道输出打开和关闭通道而不是 EOF

我试着用提琴手检查它,所以我做了一切都像火狐一样,但它仍然不起作用

当我通过腻子创建此隧道时 - 控制台应用程序有效。

感谢您的任何帮助或建议。

4

1 回答 1

0

经过两天的搜索,我找到了它!请求堆积在端口上,并且通道没有关闭,因为我忘记设置

request.KeepAlive = false;

我希望这会对某人有所帮助

于 2013-09-26T07:14:12.073 回答