Hi,
Im trying to send a files using a HTTP POST request in my Window
Application. I also have a progressbar that is being updated whil
uploading. I have managed to send a file using HTTP PUT, but not HTT
POST. I also want to send a username and password, as if it was
get?username=myuser&pass=mypass. The WebForm1.aspx is from th
following article
http://support.microsoft.com/default...;EN-US;Q323246
The code i have:
string uri = "http://localhost/WebForm1.aspx";
HttpWebRequest myrequest
(HttpWebRequest)WebRequest.Create(uri);
myrequest.SendChunked = true;
myrequest.UserAgent = "My agent";
myrequest.Method = "POST";
myrequest.ContentType = "multipart/form-data";
myrequest.AllowWriteStreamBuffering = false;
// Create a filestream
FileStream fs = new FileStream(filename, FileMode.Open
FileAccess.Read, FileShare.None);
_currentbar.Value = 0;
_currentbar.Minimum = 0;
_currentbar.Maximum = Convert.ToInt32(fs.Length);
try
{
Stream datastream = myrequest.GetRequestStream();
byte[] bytes = new byte[4096];
WriteToLog("Uploading file " + filename + " ( "
fileobj.formatSize(fs.Length) + " )", false);
currentFile.Text = Path.GetFileName(filename);
int i = fs.Read(bytes,0,bytes.Length);
while(i > 0)
{
datastream.Write(bytes, 0, bytes.Length);
updateProgressBar(i);
i = fs.Read(bytes,0,bytes.Length);
}
fs.Close();
datastream.Close();
try
{
HttpWebResponse response
(HttpWebResponse)myrequest.GetResponse();
}
catch(WebException we)
{
Console.WriteLine(we.ToString());
}
catch(NotSupportedException nse)
{
Console.WriteLine(nse.ToString());
}
}
catch(ProtocolViolationException pve)
{
Console.WriteLine(pve.ToString());
}
It wont upload the file
--
parsein
-----------------------------------------------------------------------
parseint's Profile:
http://www.msusenet.com/member.php?userid=279
View this thread:
http://www.msusenet.com/t-187057119