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

amw*_*amw 5 c#

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

错误 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。

小智 0

使用:

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "abcxx")]
Run Code Online (Sandbox Code Playgroud)

在声明方法的服务页面上,输入POST大写字母。我认为您正在输入小写字母。