I want to upload file to a server. I wrote this function to upload the file to localhost server (I am using wamp server):
private void button1_Click_1(object sender, EventArgs e)
{
FileStream fstream = new FileStream(@"C:UsersAlbertDocuments10050409_3276.doc", FileMode.OpenOrCreate);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/upload_file");
request.Method = "PUT";
request.ContentLength = fstream.Length;
request.AllowWriteStreamBuffering = true;
Stream request_stream = request.GetRequestStream();
byte[] indata = new byte[1024];
int bytes_read = fstream.Read(indata, 0, indata.Length);
while (bytes_read > 0)
{
request_stream.Write(indata, 0, indata.Length);
bytes_read = fstream.Read(indata, 0, indata.Length);
}
fstream.Close();
request_stream.Close();
request.GetResponse();
MessageBox.Show("ok");
}
So when i click on the button the exception apper said that:
Additional information: The remote server returned an error: (405) Method Not Allowed.
I tried to use "POST" instead of "PUT" so the program works and the message box appears to say 'ok', but when i open the localhost->upload_file(folder) Ididn't find any files.
I tested my program with wamp server => the problem occured.
I tested my program with real server and put in the network credentials and tried to upload to folder that has (777) permission => the problem occured.
So where is the problem exactly?
Thanks :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…