[Mono-list] Hi, and cookies problem.
Asier
asieriko@yahoo.es
Sun, 28 Nov 2004 14:56:18 +0100
Hi,
I'm new in the list. I've been trying with mono for the last months, but i've
a problem.
I've searched in google, c# forums webs, msdn, etc. but i'm not able to solve
it.
I want to login in to a web, that usese html forms, and https. This web has
also a web certificate.
When i run my program, the web returns me a cookie, but this cookie is not
enough for continue donwloading more page contents.
I've tried Firefox Live HTTP Headers extension, and using it, i can see that
the server returns 3 diferent cookies.
Can you help me?
I attach the code and firefox headers.
Thanks in advance.
Asier
//My code. It only returns one cookie.
using System.Net;
using System.IO;
using System.Text;
using System;
namespace Examples.System.Net.Cookies
{
public class CookieExample
{
public static void Main(string[] args)
{
if (args == null || args.Length != 1)
{
Console.WriteLine("Specify the URL to receive the request.");
Environment.Exit(1);
}
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("https://apliweb.uned.es/ciberuned/index.asp");
string DatosUsuario ="Login String";
byte[] datos = Encoding.Default.GetBytes(DatosUsuario);
request.Method = "POST";
request.UserAgent= "Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.6)
Gecko/20040506 Firefox/0.8";
request.Referer = "https://apliweb.uned.es/ciberuned/index.asp";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = datos.Length;
Stream sout = request.GetRequestStream();
sout.Write(datos, 0, datos.Length);
sout.Flush();
sout.Close();
// Print the properties of each cookie.
try
{
request.CookieContainer = new CookieContainer ();
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
if (request.HaveResponse)
{
WebHeaderCollection headers =
response.Headers;
foreach(string header in headers.Keys)
{
Console.WriteLine("{0}:{1}", header,
headers[header]);
}
Console.WriteLine("{0} Cookies found.",
response.Cookies.Count);
foreach(Cookie c in response.Cookies)
Console.WriteLine("{0}: {1}", c.Name,
c.Value);
}
response.Close();
}
catch (Exception ex)
{
Console.WriteLine("Exception:\n{0}\n{1}", ex.Message,
ex.StackTrace);
}
}
}
}
//Firefox headers: It returns 3 cookies.
https://apliweb.uned.es/ciberuned/index.asp
POST /ciberuned/index.asp HTTP/1.1
Host: apliweb.uned.es
User-Agent: Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.6) Gecko/20040506
Firefox/0.8
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
Accept-Language: es-es,es;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://apliweb.uned.es/ciberuned/index.asp
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
Login String