POST上的HttpWebRequest.GetResponse不允许返回405方法 [英] HttpWebRequest.GetResponse on POST returns 405 method not allowed
问题描述
大家好,
我有一个具有表单的独立应用程序,它将提示输入要连接的服务器的用户名,密码和名称(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");
}
推荐答案
通常,发生以下情况:开机自检到文件夹地址时返回"405 Method Not Allowed"错误.请尝试使用完整的正确地址,例如: http://localhost:3434/WebSite/Default.aspx
此外,请在此处查看:不允许HTTP错误405方法 [
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.
很多建议此处 [ ^ ],但基本上问题在于提供者,而不是您的代码.
Lots of suggestions here[^], but basically the issue is with the provider, not with your code.
这篇关于POST上的HttpWebRequest.GetResponse不允许返回405方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!