HTTP Post question.

A

Anthony Boudouvas

Hi to all,

i try to use Http Post to upload a file at a web server. Web server already
has a page that
it copies the uploaded file in a specifir directory.
The below code returns to me "The file name specified in the upload form
does not correspond to a valid file in the system.

Can anyone tells me if the below code is correct so to try to look in the
web server to find
what is goind wrong ?

Thanks in advance.

HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("http://dataserver/upload/uploadtester.asp");

req.Method = "POST";

Stream stream = req.GetRequestStream();

byte[] buffer = new byte[10];

int ret = 1;

FileStream fs = new FileStream("c:\\a.txt", FileMode.Open, FileAccess.Read,
FileShare.Read);

int i = fs.Read(buffer, 0 , 10);

stream.Write(buffer, 0, buffer.Length);


stream.Close();

HttpWebResponse resp = (HttpWebResponse) req.GetResponse();

StreamReader sr = new StreamReader(resp.GetResponseStream(),
Encoding.Default);

string s = sr.ReadToEnd();

Console.WriteLine(s);

resp.Close();

Console.Read();
 
J

Joerg Jooss

Anthony said:
Hi to all,

i try to use Http Post to upload a file at a web server. Web server
already has a page that
it copies the uploaded file in a specifir directory.
The below code returns to me "The file name specified in the upload
form does not correspond to a valid file in the system.

Can anyone tells me if the below code is correct so to try to look in
the web server to find
what is goind wrong ?

Thanks in advance.

HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("http://dataserver/upload/uploadtester.asp");

req.Method = "POST";

Stream stream = req.GetRequestStream();

byte[] buffer = new byte[10];

int ret = 1;

FileStream fs = new FileStream("c:\\a.txt", FileMode.Open,
FileAccess.Read, FileShare.Read);

int i = fs.Read(buffer, 0 , 10);

stream.Write(buffer, 0, buffer.Length);


stream.Close();

HttpWebResponse resp = (HttpWebResponse) req.GetResponse();

StreamReader sr = new StreamReader(resp.GetResponseStream(),
Encoding.Default);

string s = sr.ReadToEnd();

Console.WriteLine(s);

resp.Close();

Console.Read();

You really need to look at the server-side code to solve this issue. Be
aware that your code only posts the first 10 bytes of the upload file
though. Is that intended?

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top