0

I try to update an object with WEB API hosted on a remote server. I recover well the object but at the time of the change, the answer gives 404 method not Allowed. I tested to host my service in a machine of my colleague just nearby. It works well. Is what is needed to make a configuration or something else? Thank you a lot.

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) {
}

Error:

{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
}}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
ALFA
  • 263
  • 1
  • 5
  • 20

2 Answers2

0

WebDAV is know to interfere with the verb PUT. Try uninstalling WebDAV if it is present on the server and you do not use it.

DonO
  • 1,030
  • 1
  • 13
  • 27
0

It may also be that you need to contact the remote server's administrator. PUT is sometimes blocked by network switches/routers. I.e. there well may be nothing you can do to fix this with code. Try using POST instead.

Nikolay
  • 10,752
  • 2
  • 23
  • 51
  • I used angularjs as WEB client API, I kind of got the error 405 - response for preflight HAS invalid HTTP, (OPTION). there are already many similar questions but I unable to solve my case. You can see my post in http://stackoverflow.com/questions/33752356/angular-http-put-rest – ALFA Nov 17 '15 at 12:47
  • Then probably PUT (and OPTIONS?) requests are simply banned on the server (hosting) side (either by the router or admin of the target server config). Like I said, you can't do anything about it with any code, try asking the hosting provider to allow these for you. Why don't you want to consider using POST instead? Also, you can try another hosting provider that does not ban PUT requests. – Nikolay Nov 17 '15 at 12:59
  • I test the server in my localhost and I can not configure the webconfig.cs. Is POST can also work with my function updated , What is the advantage , here is my service for updating : http://stackoverflow.com/questions/33752356/angular-http-put-rest – ALFA Nov 17 '15 at 13:16
  • This is just a convention to be compatible with REST specification. No actual difference between POST and PUT in performance or anything. Just replace word "PUT" with word "POST" in your code (use $http.post in angular and [HttpPost] for controller attributes). If you are using local IIS, and can change configuration, you can enable PUT in applicationhost.config (add "PUT" to the list of the allowed requests), and disable webDAV like DonO suggested. – Nikolay Nov 17 '15 at 13:27
  • if changing put --> post : I have Failed to load resource: the server responded with a status of 415 (Unsupported Media Type) – ALFA Nov 17 '15 at 13:35