Hi,

I know its possible submit a form serverside without actually creating a html form. As you can see below:

string url = "http://websiteToSubmitTo";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string proxy = null;

string data = String.Format("parameter1={0}&parameter2={1}&parameter3={2}", parameter1, parameter2, parameter3);
byte[] buffer = Encoding.UTF8.GetBytes(data);

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.Proxy = new WebProxy(proxy, true); // ignore for local addresses
req.CookieContainer = new CookieContainer(); // enable cookies

Stream reqst = req.GetRequestStream(); // add form data to request stream
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close();

HttpWebResponse res = (HttpWebResponse)req.GetResponse();

Stream resst = res.GetResponseStream();
StreamReader sr = new StreamReader(resst);
string response = sr.ReadToEnd();

Question is how do you post a file over?

Thank you

Hmmm...okay. You know when you go to a web page and you upload a file. First you choose the file and then you click on a button to upload the file over to the server. I want to do this without actually creating the html. As you see from my original forum post you can create a http post request to post name value pairs. Question is how do you post a file over to the server? I hope this helps.

Thank you for your reply.

Or they can post their question to http://www.daniweb.com/forums/forum18.html to keep our forums organized.

yeah but it doesnt have to be webform, you can post using those c# classes within windows application. it is common to request webpage from windows application using those httpwebrequest and response classes. i think he intentionally put them in this forum.

This article has been dead for over six months. Start a new discussion instead.