在针对同一线程阅读不同的答案后,我尝试了他们讨论中提到的几乎所有选项,但是我仍然遇到错误:
错误 1:The 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# ×1