【问题标题】:How to fix this error StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1 in Asp .Net Core如何修复此错误 StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1 in Asp .Net Core
【发布时间】:2021-03-27 20:53:10
【问题描述】:

我在使用 api 发布、拉取、删除数据时遇到此错误,但我在更新记录时遇到问题,我收到此错误,我无法将数据传递给 api。

StatusCode:405,ReasonPhrase:'方法不允许',版本:1.1,内容:System.Net.Http.HttpConnection+HttpConnectionResponseContent,

代码:

public async Task<Boolean> HttpPutString(string url,int id, int qnty)
{
    var jsonString = "{\"qnty\":" + qnty+ "}";
    var content = new StringContent(jsonString, Encoding.UTF8, "application/json");

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("http://localhost/");

    var response = await client.PutAsync(url + id, content);

    if (response.StatusCode == System.Net.HttpStatusCode.NoContent)
    {
        return true;
    }
    else
    {
        return false;
    }
}

【问题讨论】:

  • 服务器正在返回响应。您需要提供源代码(最好)或相关文档。

标签: asp.net asp.net-core asp.net-core-mvc


【解决方案1】:

您是否在后端指定HTTP verb templates,例如[HttpPost] 或其他模板? 405 表示您指定了错误的HTTP verb templates。您可以删除模板,也可以将其更改为[HttpPut]。

【讨论】:

  • @Mohamed Abubakkar,你能接受这个答案,还是有其他问题?
【解决方案2】:

我面临同样的问题,请确保您调用 api Https,或确保

【讨论】:

猜你喜欢
  • 2021-01-21
  • 2014-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多