I've been searching and reading around to that and couldn't fine anything really useful.
I'm writing an small C# win app that allows user to send files to a web server, not by FTP, but by HTTP using POST. Think of it like a web form but running on a windows application.
I have my HttpWebRequest object created using something like this
HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest
and also set the Method
, ContentType
and ContentLength
properties. But thats the far I can go.
This is my piece of code:
HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
req.KeepAlive = false;
req.Method = "POST";
req.Credentials = new NetworkCredential(user.UserName, user.UserPassword);
req.PreAuthenticate = true;
req.ContentType = file.ContentType;
req.ContentLength = file.Length;
HttpWebResponse response = null;
try
{
response = req.GetResponse() as HttpWebResponse;
}
catch (Exception e)
{
}
So my question is basically how can I send a fie (text file, image, audio, etc) with C# via HTTP POST.
Thanks!
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…