C# C语言中的HTTPS代理服务器#
我正在使用HTTPS代理服务器。它应该是一个控制台应用程序。我想找一本手册或是一个例子。我找到了很多作品或是非工作样本。我尝试了MSND中SSLStream的示例,但没有成功。有人有经验或工作经验吗?代码:C# C语言中的HTTPS代理服务器#,c#,ssl,https,proxy,sslstream,C#,Ssl,Https,Proxy,Sslstream,我正在使用HTTPS代理服务器。它应该是一个控制台应用程序。我想找一本手册或是一个例子。我找到了很多作品或是非工作样本。我尝试了MSND中SSLStream的示例,但没有成功。有人有经验或工作经验吗?代码: using System; using System.Text; using System.Net.Sockets; using System.Net.Security; namespace SslTcpClient { public class SslTcpClient
using System;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;
namespace SslTcpClient
{
public class SslTcpClient
{
public static void Main(string[] args)
{
string host = "encrypted.google.com";
string proxy = "127.0.0.1";//host;
int proxyPort = 8888;//443;
byte[] buffer = new byte[2048];
int bytes;
// Connect socket
TcpClient client = new TcpClient(proxy, proxyPort);
NetworkStream stream = client.GetStream();
// Establish Tcp tunnel
byte[] tunnelRequest = Encoding.UTF8.GetBytes(String.Format("CONNECT {0}:443 HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
stream.Write(tunnelRequest , 0, tunnelRequest.Length);
stream.Flush();
// Read response to CONNECT request
// There should be loop that reads multiple packets
bytes = stream.Read(buffer, 0, buffer.Length);
Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));
// Wrap in SSL stream
SslStream sslStream = new SslStream(stream);
sslStream.AuthenticateAsClient(host);
// Send request
byte[] request = Encoding.UTF8.GetBytes(String.Format("GET https://{0}/ HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
sslStream.Write(request, 0, request.Length);
sslStream.Flush();
// Read response
do
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));
} while (bytes != 0);
client.Close();
Console.ReadKey();
}
}
}
)() 代码:
using System;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;
namespace SslTcpClient
{
public class SslTcpClient
{
public static void Main(string[] args)
{
string host = "encrypted.google.com";
string proxy = "127.0.0.1";//host;
int proxyPort = 8888;//443;
byte[] buffer = new byte[2048];
int bytes;
// Connect socket
TcpClient client = new TcpClient(proxy, proxyPort);
NetworkStream stream = client.GetStream();
// Establish Tcp tunnel
byte[] tunnelRequest = Encoding.UTF8.GetBytes(String.Format("CONNECT {0}:443 HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
stream.Write(tunnelRequest , 0, tunnelRequest.Length);
stream.Flush();
// Read response to CONNECT request
// There should be loop that reads multiple packets
bytes = stream.Read(buffer, 0, buffer.Length);
Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));
// Wrap in SSL stream
SslStream sslStream = new SslStream(stream);
sslStream.AuthenticateAsClient(host);
// Send request
byte[] request = Encoding.UTF8.GetBytes(String.Format("GET https://{0}/ HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
sslStream.Write(request, 0, request.Length);
sslStream.Flush();
// Read response
do
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));
} while (bytes != 0);
client.Close();
Console.ReadKey();
}
}
}
)() 假设您使用的是普通的HTTPS代理服务器(不是MITM代理服务器),则根本不需要任何SSL/TLS代码
它所需要的只是能够解释HTTP
CONNECT
方法,并在CONNECT
请求(例如CONNECT host.example.org:443
)中使用的主机和端口之间按原样中继通信量。假设您要的是正常的HTTPS代理服务器(不是MITM代理服务器),您根本不需要任何SSL/TLS代码
它所需要的只是能够解释HTTP
CONNECT
方法,并将流量按原样中继到CONNECT
请求中使用的主机和端口(例如CONNECT-host.example.org:443
)。查看一下mentalis代理源代码看一看mentalis代理源代码
显示您当前的代码和问题,您会得到更好的答案为什么这么多用户私刑新手?对我来说,这似乎是一个相关的问题,答案可以在50行左右给出,但很难找到,不需要向下投票。@StevendeSalas我同意你的看法。他们在世界上一直在鼓励朝着错误的方向改变。这个问题是如何得到保护并获得550张选票的?展示你当前的代码和问题,你会得到更好的答案为什么这么多用户私刑新手?对我来说,这似乎是一个相关的问题,答案可以在50行左右给出,但很难找到,不需要向下投票。@StevendeSalas我同意你的看法。他们在世界上一直在鼓励朝着错误的方向改变。这个问题是如何得到保护并获得550张选票的?这似乎不是服务器,是吗?;)这似乎不是服务器,是吗?;)