我使用以下代码将数据放到我的api中:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Baseurl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PutAsJsonAsync($"/api/Home/UpdateEmpDetails/{id}", newEmployee).Result;
if (response.IsSuccessStatusCode)
{
//...
}
}
但是我收到以下错误:
{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { X-Powered-By-Plesk: PleskWin Connection: close Date: Thu, 05 Oct 2017 05:26:07 GMT Server: Microsoft-IIS/10.0 X-Powered-By: ASP.NET Content-Length: 1293 Allow: GET Allow: HEAD Allow: OPTIONS Allow: TRACE Content-Type: text/html }}
任何人都可以帮助我吗?
答案 0 :(得分:0)
WebDAV模块可能导致405错误,因此请确保未安装WebDAV模块。检查它是否是从控制面板安装的> “打开或关闭Windows功能”。如果您不需要使用WebDAV,则删除“WebDAV Publishing”以修复“405方法不允许”问题。
或者您可以通过将以下内容添加到WebApi项目的web.config中来仅修复此项目:
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- add to remove webdav -->
</modules>