Veran estoy intentando hacer un navegador web (Sin usar el control WebBrowser) y tengo un pequeño problema al recibir la respuesta del servidor. El problema esta en que yo abro el socket, me conecto, envio la cabecera (hasta ahi perfecto), pero una vez enviada, la respuesta... "CREO" que el servidor me esta enviando la respuesta a un puerto diferente o algo asi... la cuestión es que no estoy recibiendo ninguna respuesta y no se por qué...
Aqui les muestro parte del código:
Código:
public class ClsNavegador { public ClsNavegador() {} public delegate void DelegadoLlegaronDatos(string txtHtml); public event DelegadoLlegaronDatos LlegaronDatos; private Socket _objSocket = null; private byte[] bytesDatos = new byte[1024]; public void IrAPagina(string txtUrl) { IrAPagina(txtUrl, 80); } public void IrAPagina(string txtUrl, int numPuerto) { try { _objSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _objSocket.Connect(txtUrl, numPuerto); if (!_objSocket.Connected) throw new Exception("No se ha podido establecer la conexión con: " + txtUrl); byte[] bytesEnviar = Encoding.UTF8.GetBytes(ClsPeticiones.peticionFirefox); _objSocket.BeginSend(bytesEnviar, 0, bytesEnviar.Length, SocketFlags.None, new AsyncCallback(DatosEnviado), null); _objSocket.BeginReceive(bytesDatos, 0, bytesDatos.Length, SocketFlags.None, new AsyncCallback(DatosRecibidos), _objSocket); } catch (Exception ex) { throw new Exception(ex.Message, ex); } } private void DatosRecibidos(IAsyncResult iAr) { Socket objSocket = (Socket)iAr.AsyncState; objSocket.EndReceive(iAr); string txtDatosHtml = Encoding.ASCII.GetString(bytesDatos); LlegaronDatos(txtDatosHtml); objSocket.BeginReceive(bytesDatos, 0, bytesDatos.Length, SocketFlags.None, new AsyncCallback(DatosRecibidos), objSocket); } private void DatosEnviado(IAsyncResult iAr) { _objSocket.EndSend(iAr); } } //Esto es de otra clase que es de tipo Estática ee. public static string peticionFirefox = "GET /webPrueba/index.aspx HTTP/1.1 \r\n" + "Host: localhost \r\n" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-AR; rv:1.7.5) Gecko/20041108 Firefox/1.0 \r\n" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 \r\n" + "Accept-Language: es-ar,es;q=0.8,en-us;q=0.5,en;q=0.3 \r\n" + "Accept-Encoding: gzip,deflate \r\n" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 \r\n" + "Keep-Alive: 300 \r\n" + "Connection: keep-alive \r\n";
Como pueden ver, estoy mandado una cabecera como si fuera un navegador firefox y en fin... la cuestion es que no recibo nada.
En fin, si pueden hecharme un cable, les agradecería la ayuda. Saludos.