小编amw*_*amw的帖子

远程服务器返回错误:“(405) Method Not Allowed”

在针对同一线程阅读不同的答案后,我尝试了他们讨论中提到的几乎所有选项,但是我仍然遇到错误:

错误 1The remote server returned an error: (404) Not Found.

错误二The remote server returned an error: (405) Method Not Allowed

下面是我的代码:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("URL?Paramter1=pc&user=u1&password=p1");
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
httpWebRequest.Accept = "application/json";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)

我在最后一行收到错误,即

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)

如果我使用,httpWebRequest.Method="GET"我会收到上面提到的错误号 1,如果我使用,httpWebRequest.Method="Post"我会收到错误号 2。

c#

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1