405 method not allowed Web API

前端 未结 21 1586
栀梦
栀梦 2020-11-27 18:33

This error is very common, and I tried all of the solutions and non of them worked. I have disabled WebDAV publishing in control panel and added this to my web config file:<

21条回答
  •  清酒与你
    2020-11-27 18:37

    You are POSTing from the client:

    await client.PostAsJsonAsync("api/products", product);
    

    not PUTing.

    Your Web API method accepts only PUT requests.

    So:

    await client.PutAsJsonAsync("api/products", product);
    

提交回复
热议问题