26/06/2008, 15:16
|
| Colaborador | | Fecha de Ingreso: septiembre-2007 Ubicación: San Francisco, United States
Mensajes: 3.858
Antigüedad: 17 años, 3 meses Puntos: 87 | |
Respuesta: Sockets en C# , Problemita para acceder a paginas web HttpWebRequest request;
HttpWebResponse response;
CookieContainer cookies;
#region Login Request;
string url = "https://www.tudominio.com";
string data = string.Format("parametrosdelform");
byte[] encodeddata = Encoding.ASCII.GetBytes(data);
request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = true;
request.CookieContainer = new CookieContainer();
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = encodeddata.Length;
Stream datawriter = request.GetRequestStream();
datawriter.Write(encodeddata, 0, encodeddata.Length);
datawriter.Close();
response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
if (response.StatusCode != HttpStatusCode.Found) // si falla el login
{
Console.WriteLine("Server Unreachable");
response.Close();
request.KeepAlive = false;
return string.Empty;
} |