.NET中的HTTP代理支持实际上并不支持较低级别的类,例如TcpClient或Socket。但我想通过支持“ CONNECT”命令的HTTP代理连接TCPServer(IP,端口)。
因此,我需要执行以下步骤:
CONNECT Host:Port HTTP/1.1<CR><LF><CR><LF>HTTP/1.X 200,则连接成功。其实我没有代理就这样做
TcpClient _client;
NetworkStream _stream;
public static async Task<bool> ConnectAsync(string hostname, int port)
{
_client = new TcpClient();
await _client.ConnectAsync(hostname, port).ConfigureAwait(false);
_stream = conn._client.GetStream();
..... Do some stuff
// Connexion OK
return true;
}
Run Code Online (Sandbox Code Playgroud)
在连接TcpClient之前如何使用代理和凭据?