【问题标题】:After first C# request through the ssh tunnel , second request stack on GetResponse, but browser requests work在通过 ssh 隧道的第一个 C# 请求之后,GetResponse 上的第二个请求堆栈,但浏览器请求工作
【发布时间】:2013-09-25 08:54:37
【问题描述】:

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

Tunnel 工作正常,如果在 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 时调用

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

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

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

【问题讨论】:

  • 大多数情况下,当您请求字节而没有字节时,就会发生这种情况。它会阻塞直到有新的字节。
  • 好吧,我请求的是在第一个请求中返回的脚本,如果我从浏览器请求它,每次都会返回,所以有一些字节

标签: c# firefox ssh eof tunnel


【解决方案1】:

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

request.KeepAlive = false;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2014-03-31
    • 2012-03-20
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多