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=my user&pass=mypas s. 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.Cre ate(uri);
myrequest.SendC hunked = true;
myrequest.UserA gent = "My agent";
myrequest.Metho d = "POST";
myrequest.Conte ntType = "multipart/form-data";
myrequest.Allow WriteStreamBuff ering = false;
// Create a filestream
FileStream fs = new FileStream(file name, FileMode.Open
FileAccess.Read , FileShare.None) ;
_currentbar.Val ue = 0;
_currentbar.Min imum = 0;
_currentbar.Max imum = Convert.ToInt32 (fs.Length);
try
{
Stream datastream = myrequest.GetRe questStream();
byte[] bytes = new byte[4096];
WriteToLog("Upl oading file " + filename + " ( "
fileobj.formatS ize(fs.Length) + " )", false);
currentFile.Tex t = Path.GetFileNam e(filename);
int i = fs.Read(bytes,0 ,bytes.Length);
while(i > 0)
{
datastream.Writ e(bytes, 0, bytes.Length);
updateProgressB ar(i);
i = fs.Read(bytes,0 ,bytes.Length);
}
fs.Close();
datastream.Clos e();
try
{
HttpWebResponse response
(HttpWebRespons e)myrequest.Get Response();
}
catch(WebExcept ion we)
{
Console.WriteLi ne(we.ToString( ));
}
catch(NotSuppor tedException nse)
{
Console.WriteLi ne(nse.ToString ());
}
}
catch(ProtocolV iolationExcepti on pve)
{
Console.WriteLi ne(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