Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a standalone application having a form, which will be prompting for username, password and the name (IP) of the server to connect to. On entering the details, it should connect to that particular server (Windows server) and should be able to upload the required files to a physical folder in the windows server. But HttpWebRequest.GetResponse on POST returns 405 method not allowed error. Any help is appreciated.

Thanks in advance

Below is the code snippet
C#
private void Login(string UID, string PWD)
        {
            string strreq = WriteLoginReqXML(UID, PWD);
            string ct = "http://" + comboBox1.Text;            
            string ct1 = comboBox1.Text;
            Uri ur = new Uri(ct);
            UriBuilder MSPage = new UriBuilder();
            MSPage.Scheme = "http";
            MSPage.Host = ct1;
            MSPage.Port = 80;
            Uri CompletedUri = MSPage.Uri;
            HttpWebRequest request =         (HttpWebRequest)WebRequest.Create(CompletedUri);
            String windowsAuthType = "Basic";

            CredentialCache cache = new CredentialCache();
            cache.Add(ur,windowsAuthType,new NetworkCredential(UID,PWD));
            request.ContentType = "application/x-www-form-urlencoded";

            request.Credentials = cache;
            request.PreAuthenticate = true;
            request.Method = "POST";
         
            request.ContentType = "application/x-www-form-urlencoded";

            string strBuffer = "Ghi";

            byte[] buffer = Encoding.ASCII.GetBytes(strBuffer);

            request.ContentLength = buffer.Length;

            Stream PostData = request.GetRequestStream();

            PostData.Write(buffer, 0, buffer.Length); 

            PostData.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode != HttpStatusCode.OK)
                    MessageBox.Show("OK");
}
Posted
Updated 9-May-12 22:33pm
v2

Generally, it happens that "405 Method Not Allowed" error is returned when POSTing to folder addresses. Try with full proper address, like: http://localhost:3434/WebSite/Default.aspx

Further, have a look here: HTTP Error 405 Method not allowed[^] - what it means and how it can be resolved.
 
Share this answer
 
Lots of suggestions here[^], but basically the issue is with the provider, not with your code.
 
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