¿Cómo conectarse al proxy HTTPS?
Estoy intentando conectarme al servidor HTTPS a través del proxy usando sockets. Hasta donde sé, cuando se usa el proxy HTTP, uno debe conectar el socket y luego interactuar con él, ya que es el servidor real. Con HTTP, este enfoque funciona, pero con HTTPS no. ¿Por qué
Aquí hay un programa simple que se conecta al servidor HTTPS
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;
// Connect socket
TcpClient client = new TcpClient(proxy, proxyPort);
// Wrap in SSL stream
SslStream sslStream = new SslStream(client.GetStream());
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);
sslStream.Flush();
// Read response
byte[] buffer = new byte[2048];
int bytes;
do
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));
} while (bytes != 0);
client.Close();
Console.ReadKey();
}
}
}
Se conecta con éxito cuandoproxy = host
yproxyPort = 443
. Pero cuando los configuré en 127.0.0.1:8888 (proxy fiddler en localhost) no funciona. El programa se cuelga ensslStream.AuthenticateAsClient(host);
¿Por qué? Fiddler admite HTTPS (los navegadores pueden conectarse a través de él).
PD. No, no puedo usarHttpWebRequest
en mi caso