Results 1 to 5 of 5

Thread: [RESOLVED] Using webclient to upload a file to a server

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [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,
    steve

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    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:
    1. wc.UpLoadFile(url, "PUT", filename)

    Many thanks,
    steve

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Using webclient to upload a file to a server

    Deleted
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width