[RESOLVED] Using webclient to upload a file to a server
Hello,
I am using the code below to upload a file to a server running windows IIS 5.1.
I am just testing on my own computer to see if this works ok. However, I keep getting the following error message:
Code:
The remote server returned an error (405) Method Not Allowed
I am sure this is a IIS problem maybe something to so with permissions. However, I am configure the virtual directory to allow read, write, and directory browsing.
The config.xml file I am trying to upload is located in the same directory as the executable and does exist.
Code:
Private Sub upload_config_to_server()
Dim url As New Uri("http://localhost/softphone/config.xml")
Dim wc As New WebClient()
If Not wc.IsBusy Then
Try
wc.UploadFile(url, Nothing, "config.xml")
Catch webex As WebException
Console.WriteLine("Web Exception {0}", webex.Message)
Catch ex As Exception
Console.WriteLine("Exception {0}", ex.Message)
End Try
End If
End Sub
Many thanks for any advice,
Re: Using webclient to upload a file to a server
You can't just upload a file to an HTTP server. You're trying to treat it like an FTP server. To upload using HTTP you must make a request to an action using the POST method. That action must be a script of some sort that can accept the file contents and do the appropriate thing with it. Otherwise, anyone could upload anything to any web site.
Re: Using webclient to upload a file to a server
Thanks for your input.
I have resolved this issue by passing the PUT method in the webclient UpLoadFile method. This seems to work ok. However, is using PUT not the recommended way of doing this?
vb Code:
wc.UpLoadFile(url, "PUT", filename)
Many thanks,
Re: Using webclient to upload a file to a server
Never used it before myself. Sounds like it may well be the method that allows you to just upload a file directly, rather than having code to do it with a POST. I'm guessing that allowing such access opens up your web site to security issues though.
Re: Using webclient to upload a file to a server