在阅读了同一主题的不同答案后,我几乎尝试了他们讨论中提到的所有选项,但我仍然收到错误:
Error No1:The remote server returned an error: (404) Not Found.
OR
Error No2The 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();
我在最后一行收到错误,即
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
如果我使用httpWebRequest.Method="GET"
,我会收到如上所述的错误号1,如果我使用httpWebRequest.Method="Post"
,我会收到错误号2。
发布于 2014-11-22 14:34:30
使用:
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "abcxx")]
在声明方法的服务页面中,以大写字母键入POST
。我想你是在用小写字母打字。
发布于 2015-10-14 17:29:30
我也面临着这个问题。此错误的根本原因可能是web配置文件中的终结点地址不正确。
这是我错误的web配置
<services>
<service behaviorConfiguration="mexBehavior" name="sample.sample">
<endpoint address="http://xxx.xxx.x.xxx:9335" binding="basicHttpBinding" contract="sample.Isamplebase" />
<host>
<baseAddresses>
<add baseAddress="http://xxx.xxx.x.xxx:9335" />
</baseAddresses>
</host>
</service>
</services>
应该是这样的
<services>
<service behaviorConfiguration="mexBehavior" name="sample.sample">
<endpoint address="http://xxx.xxx.x.xxx:9335/sample.svc" binding="basicHttpBinding" contract="sample.Isamplebase" />
<host>
<baseAddresses>
<add baseAddress="http://xxx.xxx.x.xxx:9335" />
</baseAddresses>
</host>
</service>
</services>
现在它工作得很好。最好的是你的..祝好运。
发布于 2016-10-25 07:09:05
我敢打赌,Paramter1、用户名或密码都不正确--换句话说,您试图使用的用户is不存在。
服务器返回404Not Found,不是因为你没有找到正确的API方法,而是因为你请求的对象不存在。
https://stackoverflow.com/questions/23213967
复制相似问题