HELP!!! Getting page via POST/Passing variables

M

me

How can I request a web page using POST while passing some
variables? Like I want to access

http://www.localhost.com/info.aspx

with POST and with variables info=0 and set=1 ?

I have tried stupid HttpWebRequest BUT it is NOT
WORKING ... I posted the question few days back BUT nobody
answered it... GURU PPL where ARE YOU???

me doing this..




string lcUrl = "http://localhost/test.php";
HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create
(lcUrl);


string lcPostData = "info=" +
System.Web.HttpUtility.UrlEncode("0") + "&set=" +
System.Web.HttpUtility.UrlEncode("1");

loHttp.Method="POST";

byte [] lbPostBuffer = System.Text.Encoding.GetEncoding
(1252).GetBytes(lcPostData);

loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Length);
loPostData.Flush();
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();
System.Text.Encoding enc = System.Text.Encoding.GetEncoding
(1252);
StreamReader loResponseStream = new StreamReader
(loWebResponse.GetResponseStream(),enc);

string lcHtml = loResponseStream.ReadToEnd();
Console.Write(lcHtml);
loWebResponse.Close();
loResponseStream.Close();
 
M

Michael Giagnocavo [MVP]

Look at the WebClient class. Also, use Google Groups and search, as there
are many examples already written (for WebClient or HttpWebRequest).
-mike
MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top