Web API - 405 - The requested resource does not support http method 'PUT'

前端 未结 10 637
说谎
说谎 2020-12-01 14:10

I have a Web API project and I am unable to enable \"PUT/Patch\" requests against it.

The response I get from fiddler is:


HTTP/1.1 405 Method Not Al         


        
10条回答
  •  渐次进展
    2020-12-01 14:52

    Maybe it's late now, but someone can use this.

    I wanted to use PUT request and I just sent stringified object to web api and in put method only accepted that object.

    JQUERY

    let musterija = {
                Name: name,
                Email: email,
                Password: password,
                Username: logUser.Username,
                Lastname: lastname,
                GenderString: gender,
                Jmbg: identification,
                PhoneNumber: phone,
            };
    
            $.ajax({
                method: "PUT",
                url: "/api/Musterija",
                data: JSON.stringify(musterija),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function () {
                    alert("Entity updated");
                    EmptyAllInputs();
                    $('#divprofile').show();
                    $('#divupdate').hide();
                },
                error: function (msg) {
                    alert("Fail - " + msg.responseText);
                }
            });
    

    WEB API

        [HttpPut]
        public HttpResponseMessage PutMusterija(Musterija m)
    

提交回复
热议问题