Solved

Getting error 405 method not allowed when trying to "POST" a .txt file to a directory on my IIS 6 server with .Net webclient

Posted on 2006-11-08
5
1,031 Views
Last Modified: 2012-08-14
I need to be able to download and upload some text files to a directory on our IIS web server. I can't use ftp because of firewall restriction so it has to be http. I can connect and download the files using the .Net webclient.DownloadFile() just fine. But when I try to use the webclient.UploadFile() I get the "(405) method not allowed" error. The write permissions are enabled on the website. Is there some other permissions or a configuration change that I need to make on the website?
0
Comment
Question by:defranz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 3

Expert Comment

by:tang_tzuchi
ID: 17904690
Hi,

You can try to use the Put method instead of Post method to upload your file.
0
 
LVL 3

Expert Comment

by:tang_tzuchi
ID: 17904704
below was some reference for the similar problems.......

http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=511698&SiteID=17
0
 

Author Comment

by:defranz
ID: 17909462
I had already tried the using the PUT option instead of the default POST among many other things. I had to do a lot of other reading and searching and I was able to figure out that the real problem was a 401 error which was causing the server to give me the 405 error.

I didn't have the time to add this to the question description last night, but here is what the program is doing.

It is a remote program on one of our remote locations. It is automatically started and downloads the text files from our server to the remote PC. Then it imports the text files into the database and does the processing that it needs to. When it is done it uploads the response text files back to our server. The folder on the server is secured and the site is not browseable so that you would have to know that the folder exists in order to upload to it for security reasons.

The problem was that I was not assigning any headers to the webclient and the server was not recognizing the webclient as a recognized program and I think it was dropping the session and credentials after it initially logged in. After checking the logs on the server I noticed that it would initially login OK and then when I tried to post it would give me two different 401 errors and then the 405 because it didn't have the security to write to the folder. I did have to use the "PUT" method though. The "POST" method will not work.

Here is the general C# code that I used so that others who encounter this problem will hopefully have to do less searching.

To upload:

// setup the webclient
WebClient Client = new WebClient ();
NetworkCredential myCredentials = new NetworkCredential("username","password"); // security credentials
Client.Credentials = myCredentials;
Client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

// upload the file                  
byte[] responseArray = Client.UploadFile("http://some server name/name of the file after it is uploaded to the server","PUT",@"location of the file to upload");

// to download just use Client.DownloadFile() instead

Have a great day. Mine just got better! :)
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17964660
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question