I am able to post data to a form so long as its strings. by creating a dictinary of keys and values, then creating a string in the style of key+ "=" + value "+ & repeat. then passing it to a method kinda like

private string PostData(string url, string postData)
HttpWebRequest request=null;

Uri uri = new Uri(url);
request = (HttpWebRequest) WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
using(Stream writeStream = request.GetRequestStream())
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);

string result=string.Empty;
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8))
result = readStream.ReadToEnd();
return result;

but this doesn't work for files.

I am working on an application that is going to make it DIRT simple for my friends and family to quickly edit, crop, resize, and optimize for email, pictures from a digital camera. then using my web server for my website, so the users don't have to worry about smtp server stuff, the app will automatically zip and email the pictures just by specifying the address to send it to.

i have finished a asp file that will accept a multipart form's post data. automatically uploading any "file" type data to a temp diretory, and then emailing the files to the email address sent to it. then deleting the temp data. It works great so long as I use a simple form and let the browser handle the post. but I can't seem to figure out how to do it in my C# application.

If anyone could help me out with how this is done i would appreciate it. Google isn't cooperating with me today.

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.