1

I try to consume a Web service with REST angular ($ http). The GET is OK, but when I try to make a change with $ http.put, the error appears below:

XMLHttpRequest cannot load http://10.2.150.238:90/api/Collaborateurs/1. Response for preflight has invalid HTTP status code 405.
enter image description here

update function :

.factory('UpdateCollaborateur', function ($http, config) {
    var fac = {};
    fac.Update = function (matricule,collaborateur) {
        return $http.put(config.apiUrl + 'Collaborateurs/'+ matricule, collaborateur);

    };
    return fac;
})

WEB API 2 , put :

 public IHttpActionResult PutCollaborateur(int id, Collaborateur collaborateur)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != collaborateur.matricule_collaborateur)
            {
                return BadRequest();
            }

            db.Entry(collaborateur).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CollaborateurExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }

Header of my fonction :

 [ResponseType(typeof(void))]

What is this problem?? Thanks

10
  • what restfull service doe you have? Commented Nov 17, 2015 at 8:43
  • You could try this: stackoverflow.com/questions/33660712 Commented Nov 17, 2015 at 8:49
  • my Service : WEB API 2 Commented Nov 17, 2015 at 8:49
  • 2
    What's unclear about the error message? Your browser is making a preflight OPTIONS request. The server is saying that OPTIONS requests are unacceptable. Commented Nov 17, 2015 at 8:54
  • 1
    The preflight request mentioned by @Quentin happens as a part of CORS implementation - developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS. Also worth reading what 405 HTTP code means - checkupdown.com/status/E405.html Commented Nov 17, 2015 at 8:58

1 Answer 1

1

405 means that the method is not allowed

If you use [HttpPut] make sure that's your webconfig.xml allows it

Try the following

<system.webServer>
    <handlers>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.