首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >远程服务器返回错误:"(405)方法不允许“

远程服务器返回错误:"(405)方法不允许“
EN

Stack Overflow用户
提问于 2014-04-22 16:08:31
回答 4查看 17.6K关注 0票数 5

在阅读了同一主题的不同答案后,我几乎尝试了他们讨论中提到的所有选项,但我仍然收到错误:

Error No1The 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。

EN

回答 4

Stack Overflow用户

发布于 2014-11-22 14:34:30

使用:

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "abcxx")]

在声明方法的服务页面中,以大写字母键入POST。我想你是在用小写字母打字。

票数 0
EN

Stack Overflow用户

发布于 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>

现在它工作得很好。最好的是你的..祝好运。

票数 0
EN

Stack Overflow用户

发布于 2016-10-25 07:09:05

我敢打赌,Paramter1、用户名或密码都不正确--换句话说,您试图使用的用户is不存在。

服务器返回404Not Found,不是因为你没有找到正确的API方法,而是因为你请求的对象不存在。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23213967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档