Para entender realmente la parte interna del protocolo HTTP se puede utilizar TcpClient clase:
using (var client = new TcpClient("www.google.com", 80))
{
using (var stream = client.GetStream())
using (var writer = new StreamWriter(stream))
using (var reader = new StreamReader(stream))
{
writer.AutoFlush = true;
// Send request headers
writer.WriteLine("GET/HTTP/1.1");
writer.WriteLine("Host: www.google.com:80");
writer.WriteLine("Connection: close");
writer.WriteLine();
writer.WriteLine();
// Read the response from server
Console.WriteLine(reader.ReadToEnd());
}
}
Otra posibilidad es activate tracing poniendo lo siguiente en su app.config
y simplemente use WebClient para realizar una solicitud HTTP:
<configuration>
<system.diagnostics>
<sources>
<source name="System.Net" tracemode="protocolonly">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<switches>
<add name="System.Net" value="Verbose"/>
</switches>
<sharedListeners>
<add name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="network.log" />
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>
</configuration>
A continuación, puede realizar una llamada HTTP:
using (var client = new WebClient())
{
var result = client.DownloadString("http://www.google.com");
}
Y, por último analizar el tráfico de red en el archivo network.log
generado. WebClient
también seguirá redireccionamientos HTTP.
Ejemplo impresionante, estoy ansioso por probarlo. Esta es una gran manera de visualizar lo que está pasando. Gracias – Jeff