[Mono-list] WebRequest problems
Asier Urio Larrea
asieriko at gmail.com
Mon Apr 17 14:44:21 EDT 2006
Hi,
I hope this helps:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(host);
string PostData ="usr=" + usr + "&pass=" + pass; // the post values tha we
send
request.CookieContainer = new CookieContainer ();
ServicePointManager.CertificatePolicy = new CertPolicy();
byte[] data = Encoding.Default.GetBytes(PostData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
//send the post data
Stream sout = request.GetRequestStream();
sout.Write(data, 0, data.Length);
sout.Flush();
sout.Close();
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
//save the cookies
CookieContainer ContenedorCookies = new CookieContainer ();
foreach(Cookie c in response.Cookies)
ContenedorCookies.Add( new Cookie (c.Name, c.Value));
//now the second request
request = (HttpWebRequest) WebRequest.Create(2ndrequest);
request.CookieContainer = ContenedorCookies; //with the cookies we've
response = (HttpWebResponse) request.GetResponse();
Stream stream = response.GetResponseStream ();
StreamReader reader = new StreamReader(stream);
string web = reader.ReadToEnd();
reader.Close();
El Lunes 17 Abril 2006 18:49, wibble wibble escribió:
> 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!
More information about the Mono-list
mailing list