[英]The remote server returned an error: "(405) Method Not Allowed"
After reading different answers against the same thread i tried almost all the options mentioned in their discussions however i am still getting error:在阅读了针对同一线程的不同答案后,我尝试了他们讨论中提到的几乎所有选项,但是我仍然遇到错误:
Error No1 : The remote server returned an error: (404) Not Found.
错误 No1 :
The remote server returned an error: (404) Not Found.
OR或者
Error No2 : The remote server returned an error: (405) Method Not Allowed
.错误2:
The remote server returned an error: (405) Method Not Allowed
。
Below is my code:下面是我的代码:
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();
I receive error on the last line ie我在最后一行收到错误,即
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
If i use httpWebRequest.Method="GET"
i receive the error number 1 as mentioned above and if i use httpWebRequest.Method="Post"
i receive the error number 2.如果我使用
httpWebRequest.Method="GET"
我收到上面提到的错误号 1,如果我使用httpWebRequest.Method="Post"
我收到错误号 2。
Use:用:
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "abcxx")]
At your service page where you declare your method, type POST
in upper case.在您声明方法的服务页面上,以大写形式键入
POST
。 I think you are typing in lowercase.我认为您正在输入小写字母。
I too face this issue.我也面临这个问题。 Root cause of this error is may be mistook endpoint address in web config file..
此错误的根本原因可能是 Web 配置文件中的端点地址错误。
This is my mistaken web config这是我错误的网络配置
<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>
It should be like this应该是这样的
<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>
Now its working fine... Best is yours.. Good Luck.现在它工作正常......最好的是你的......祝你好运。
My bet is that either Paramter1 or username or password are incorrect - in other words the user you were trying to use doid not exist.我敢打赌 Paramter1 或用户名或密码不正确 - 换句话说,您尝试使用的用户不存在。
The server returns 404 Not Found , not because you didn't hit the right API method, but because the object you are asking for doesn't exist.服务器返回404 Not Found ,不是因为您没有找到正确的 API 方法,而是因为您请求的对象不存在。
Looking at your code, you create your URL and pass data as url form encoded, but then you set the content type as application/json
.查看您的代码,您创建了 URL 并将数据作为 url 表单编码传递,但随后将内容类型设置为
application/json
。 I'd think you either:我认为你要么:
application/x-www-form-urlencoded
as the content typeapplication/x-www-form-urlencoded
作为内容类型or或者
I also faced this issue.我也遇到过这个问题。 In my case the reason was in incorrect (incomplete) URL.
在我的情况下,原因是不正确(不完整)URL。
I called我打了电话
60033/COMPANY_NAME/api/Company/MOM/v1.0/companies(5a56e3ea-cd63-ec11-b6ea-6045bd874170)/ 60033/COMPANY_NAME/api/Company/MOM/v1.0/companies(5a56e3ea-cd63-ec11-b6ea-6045bd874170)/
But you can't do a POST on the general companies-URL.但是您不能在一般公司 URL 上进行 POST。
I should use URL different headers, depends on my purpose我应该使用 URL 不同的标题,取决于我的目的
60033/COMPANY_NAME/api/Company/MOM/v1.0/companies(5a56e3ea-cd63-ec11-b6ea-6045bd874170)/receiptHeaders 60033/COMPANY_NAME/api/Company/MOM/v1.0/companies(5a56e3ea-cd63-ec11-b6ea-6045bd874170)/receiptHeaders
When I fixed URL errors are gone当我修复 URL 错误消失了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.