Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i hit URL to download a zipfile in given address it throw an error of "405 Method not Allowed"
C#
//web client class is used for sending data to and receiving data from a resource identified by a postal one uri.  
using (var httpClient = new WebClient())
{
    //download the Labeling List file resource with the specified URI to a local file.
    IWebProxy objProxy = new WebProxy("proxy.myproxy.com");
    httpClient.Proxy = objProxy;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    httpClient.Credentials = new NetworkCredential("username", "password");

httpClient.DownloadFile("https://fast.usps.com/fast/labelListFileDownloadFile.action?fileName=ALL_LABELS.ZIP" , LoggingHandler.LabelingListDataPath + GetFilename(filenames.LabelingListFile));
    httpClient.Dispose();
}
Posted
Updated 14-Mar-13 0:30am
v3

The browser will issue a GET request for your resource, the server you are calling is telling you that the POST method is not allowed for the URL you are trying to call. By passing in the path portion of your URL as the Request object data parameter you are making this a POST instead of a GET.

See http://stackoverflow.com/questions/11453078/why-am-i-getting-http-error-405-method-not-allowed-when-requesting-a-url-usin[^]

And also see the possible reasons of HTTP Error 405 Method not allowed[^]


--Amit
 
Share this answer
 
C#
using (var httpClient = new WebClient())
{
    //download the Labeling List file resource with the specified URI to a local file.
    IWebProxy objProxy = new WebProxy("proxy.myproxy.com", 1234);
    httpClient.Proxy = objProxy;
    httpClient.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22"); 
httpClient.DownloadFile("https://fast.usps.com/fast/labelListFileDownloadFile.action?fileName=ALL_LABELS.ZIP" , LoggingHandler.LabelingListDataPath + GetFilename(filenames.LabelingListFile));
    httpClient.Dispose();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900