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
945 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
  • 2
5 Comments
 
LVL 3

Expert Comment

by:tang_tzuchi
Comment Utility
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
Comment Utility
below was some reference for the similar problems.......

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

Author Comment

by:defranz
Comment Utility
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
Comment Utility
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now