public RespuestaHTTP(String url, ParametroGet[] parametros) { this.setURL(url); this.parametros = parametros; this._correcto = true; }
public RespuestaHTTP Escucha() { try{ client = listener.AcceptTcpClient(); DDebug.WriteLine("Conexion establecida"); stream = client.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); stream.ReadTimeout = 30000; // limpiar stream string entrada = ""; while (entrada.Length < 4 || entrada.Substring(entrada.Length - 4, 4) != "\r\n\r\n") { entrada += (char)reader.Read(); } DDebug.WriteLine(entrada); stream.Flush(); string GETurl = entrada.Substring(0, entrada.IndexOf("\r\n")); if (GETurl != null) { string pattern = " (.*?) HTTP"; MatchCollection matches = Regex.Matches(GETurl, pattern); string url = ""; if (matches.Count > 0) { GroupCollection gc = matches[0].Groups; CaptureCollection cc = gc[1].Captures; url = cc[0].Value; } DDebug.WriteLine(url); pattern = "\\?(&?([^=^&]+?)=([^&]*))*"; matches = Regex.Matches(url, pattern); //Utilidades.print_r_regex(matches); if (matches.Count > 0) { GroupCollection gc = matches[0].Groups; CaptureCollection variables = gc[2].Captures; CaptureCollection valores = gc[3].Captures; ParametroGet[] parametros = new ParametroGet[variables.Count]; for (int i = 0; i < variables.Count; i++) { parametros[i] = new ParametroGet( Uri.UnescapeDataString(variables[i].Value).Replace("+", " "), Uri.UnescapeDataString(valores[i].Value).Replace("+", " ")); } return(new RespuestaHTTP(url, parametros)); } return(new RespuestaHTTP(url)); } return(new RespuestaHTTP(false)); } catch (Exception e) { Console.WriteLine("h1"); Console.WriteLine(e); CierraCliente(); return(new RespuestaHTTP(false)); } }
public RespuestaHTTP Escucha() { try{ client = listener.AcceptTcpClient (); DDebug.WriteLine ("Conexion establecida"); stream = client.GetStream (); reader = new StreamReader (stream); writer = new StreamWriter (stream); stream.ReadTimeout = 30000; // limpiar stream string entrada = ""; while (entrada.Length < 4 || entrada.Substring(entrada.Length - 4, 4) != "\r\n\r\n") { entrada += (char) reader.Read(); } DDebug.WriteLine(entrada); stream.Flush(); string GETurl = entrada.Substring(0, entrada.IndexOf("\r\n")); if(GETurl != null){ string pattern = " (.*?) HTTP"; MatchCollection matches = Regex.Matches (GETurl, pattern); string url=""; if (matches.Count > 0) { GroupCollection gc = matches[0].Groups; CaptureCollection cc = gc[1].Captures; url = cc[0].Value; } DDebug.WriteLine (url); pattern = "\\?(&?([^=^&]+?)=([^&]*))*"; matches = Regex.Matches (url, pattern); //Utilidades.print_r_regex(matches); if (matches.Count > 0) { GroupCollection gc = matches[0].Groups; CaptureCollection variables = gc[2].Captures; CaptureCollection valores = gc[3].Captures; ParametroGet[] parametros = new ParametroGet[variables.Count]; for(int i = 0; i < variables.Count; i++){ parametros[i] = new ParametroGet( Uri.UnescapeDataString(variables[i].Value).Replace("+", " "), Uri.UnescapeDataString(valores[i].Value).Replace("+", " ")); } return new RespuestaHTTP (url, parametros); } return new RespuestaHTTP (url); } return new RespuestaHTTP (false); } catch(Exception e){ Console.WriteLine ("h1"); Console.WriteLine (e); CierraCliente (); return new RespuestaHTTP (false); } }