このライブラリで 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 ではありません
フィドラーで確認しようとしたので、すべてをFirefoxのように作成しましたが、それでも機能しません
パテでこのトンネルを作成すると、コンソールアプリが機能します。
助けや提案をありがとう。