teixeira Posted July 10, 2006 Posted July 10, 2006 Hi, I have a webpage called print.cgi, that basically prints in paper the text i send in a TextField inside a form called "my_form" with the POST method, and i would like to get this page in my c# windows form application and send to the instruction to print this page a text in the POST variable. how can i do this? Greetings Tiago Teixeira Quote
Gill Bates Posted July 10, 2006 Posted July 10, 2006 StringBuilder builder = new StringBuilder(); builder.Append("name="); builder.Append(System.Web.HttpUtility.UrlEncode("Gill Bates")); builder.Append("&country="); builder.Append(System.Web.HttpUtility.UrlEncode("United States")); byte[] data = Encoding.ASCII.GetBytes(builder.ToString()); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:4087/post_test/form.aspx")); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; Stream stream = request.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); Console.WriteLine(reader.ReadToEnd()); reader.Close(); response.GetResponseStream().Close(); Quote
teixeira Posted July 10, 2006 Author Posted July 10, 2006 Hi, Thanks 4 all, perfect. It rocks. I just had a problem about the athentication but i added the right network credentials to the HttpWebRequest and i worked. Thanks for the precious help, one more ;) Regards, Tiago Teixeira Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.