本文介绍了POST上的HttpWebRequest.GetResponse不允许返回405方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个具有表单的独立应用程序,它将提示输入要连接的服务器的用户名,密码和名称(IP).输入详细信息后,它应该连接到该特定服务器(Windows服务器),并且应该能够将所需文件上传到Windows服务器中的物理文件夹.但是POST上的HttpWebRequest.GetResponse返回405方法不允许错误.任何帮助表示赞赏.
在此先感谢
下面是代码片段
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
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");
}
推荐答案
这篇关于POST上的HttpWebRequest.GetResponse不允许返回405方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!