Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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();

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...