[Mono-list] WebRequest problems

Asier Urio Larrea asieriko at yahoo.es
Mon Apr 17 19:04:34 EDT 2006


Hi,
I hope this helps:


HttpWebRequest request =3D (HttpWebRequest) WebRequest.Create(host);=20
string PostData =3D"usr=3D" + usr + "&pass=3D" + pass; // the post values t=
ha we=20
send
request.CookieContainer =3D new CookieContainer ();
ServicePointManager.CertificatePolicy =3D new CertPolicy();
				=09
byte[] data =3D Encoding.Default.GetBytes(PostData);=20
request.Method =3D "POST";=20
request.ContentType =3D "application/x-www-form-urlencoded";=20
request.ContentLength =3D data.Length;=20
					=09
//send the post data
Stream sout =3D request.GetRequestStream();=20
sout.Write(data, 0, data.Length);=20
sout.Flush();=20
sout.Close();=20

HttpWebResponse response =3D (HttpWebResponse) request.GetResponse();

//save the cookies
CookieContainer ContenedorCookies =3D new CookieContainer ();
				=09
foreach(Cookie c in response.Cookies)
	ContenedorCookies.Add( new Cookie (c.Name, c.Value));

//now the second request
request =3D (HttpWebRequest) WebRequest.Create(2ndrequest);=20

request.CookieContainer =3D ContenedorCookies;  //with the cookies we've
response =3D (HttpWebResponse) request.GetResponse();
Stream stream =3D response.GetResponseStream ();

StreamReader reader =3D new StreamReader(stream);
string web =3D reader.ReadToEnd();
reader.Close();


El Lunes 17 Abril 2006 18:49, wibble wibble escribi=C3=B3:
>  I cannot see how to do this. I've searched the web and found the solution
> to parts of the problem but I can't figure out how to put it togerther.
>
> I need to send post values to a server and record the cookies that are
> returned.I then need to create a new HttpWebRequest and send the cookies
> that I just received with the new HttpWebRequest.
>
> so...
>
> 1)HttpWebRequest 1 connects to server and gets cookies
> 2)HttpWebRequest 2 uses the cookies that HttpWebRequest 1 has and connects
> to the server with those cookies
> 3)get the page HTML returned with HttpWebRequest 2
>
>
> i've managed to get some parts working. I think I can recored the cookies,
> but i don't know how to send the post values, and I certainly don't know
> how to put it together.
>
>
>
>
> Thanks for any help!

		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com


More information about the Mono-list mailing list