P
Peter Bladh
Hi
I found a really good example here by Alex Feinman that describes who to
upload a file with PUT.
But I need to upload the file with POST and don't get it to work. I get
(500) Internal Server Error. Here's the code (I've also tried with some
other headers)
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
BinaryReader rdr = new BinaryReader(File.OpenRead(FileToUpload));
byte[] data = rdr.ReadBytes((int)rdr.BaseStream.Length);
req.Method = "POST";
req.ContentType = "application/octet-stream";
req.SendChunked = true;
req.Timeout = 10000;
req.ContentLength = data.Length;
req.KeepAlive = true;
Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Console.WriteLine(res.ToString());
res.Close();
/peter bladh
I found a really good example here by Alex Feinman that describes who to
upload a file with PUT.
But I need to upload the file with POST and don't get it to work. I get
(500) Internal Server Error. Here's the code (I've also tried with some
other headers)
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
BinaryReader rdr = new BinaryReader(File.OpenRead(FileToUpload));
byte[] data = rdr.ReadBytes((int)rdr.BaseStream.Length);
req.Method = "POST";
req.ContentType = "application/octet-stream";
req.SendChunked = true;
req.Timeout = 10000;
req.ContentLength = data.Length;
req.KeepAlive = true;
Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Console.WriteLine(res.ToString());
res.Close();
/peter bladh