HTTP 客户端 putAsync(错误 404 方法不允许)
HTTP Client putAsync (Error 404 Method not Allowed)
我尝试使用托管在远程服务器上的 WEB API 更新对象。我很好地恢复了对象,但在更改时,答案给出了 404 方法不允许。我测试了在附近同事的机器上托管我的服务。它运作良好。是需要做配置还是其他什么?
非常感谢。
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage responsse = client.PutAsJsonAsync("api/Collaborateurs/" + coll.matricule_collaborateur, coll).Result;
if (responsse.IsSuccessStatusCode) {
}
错误:
{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Thu, 12 Nov 2015 14:28:10 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Content-Length: 1343
Allow: GET
Allow: HEAD
Allow: OPTIONS
Allow: TRACE
Content-Type: text/html
}}
已知 WebDAV 会干扰动词 PUT。如果服务器上存在 WebDAV 而您不使用它,请尝试卸载它。
也可能是您需要联系远程服务器的管理员。 PUT 有时会被网络 switches/routers 阻止。 IE。 你 可能无法用代码解决这个问题。请尝试使用 POST。
我尝试使用托管在远程服务器上的 WEB API 更新对象。我很好地恢复了对象,但在更改时,答案给出了 404 方法不允许。我测试了在附近同事的机器上托管我的服务。它运作良好。是需要做配置还是其他什么? 非常感谢。
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage responsse = client.PutAsJsonAsync("api/Collaborateurs/" + coll.matricule_collaborateur, coll).Result;
if (responsse.IsSuccessStatusCode) {
}
错误:
{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Thu, 12 Nov 2015 14:28:10 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Content-Length: 1343
Allow: GET
Allow: HEAD
Allow: OPTIONS
Allow: TRACE
Content-Type: text/html
}}
已知 WebDAV 会干扰动词 PUT。如果服务器上存在 WebDAV 而您不使用它,请尝试卸载它。
也可能是您需要联系远程服务器的管理员。 PUT 有时会被网络 switches/routers 阻止。 IE。 你 可能无法用代码解决这个问题。请尝试使用 POST。