c# - 使用 RestSharp 时,我在 POST 上收到 MethodNotFound 但响应认为它是 GET?

标签 c# restsharp methodnotfound

我正在使用 RestSharp 并第一次执行 POST 我有许多 GET 请求都可以正常工作)。休息服务是在 python 中,但我认为这对这个问题并不重要。这是我的代码:

   var client = new RestClient { BaseUrl = _baseUrl };

  var request = new RestRequest("nameOfPostMethod", Method.POST);
  request.RequestFormat = DataFormat.Json;
  request.AddBody(new { name, description });
  request.AddHeader("accept", "application/json");

  var response = client.Execute(request);

这是我得到的原始响应:

    [{"name": "405 - Method Not Allowed", "data": 
    [["Class", "werkzeug.exceptions.MethodNotAllowed"], ["Category", "Client Error"], 
     ["Code", "405"], ["Name", "Method Not Allowed"], ["request.method", "GET"], 
     ["request.url", "http://myUrl/nameOfPostMethod"], ["error.message", "405 Method
    Not Allowed"], ["error.description", null]]}]

让我印象深刻的是这些行,它似乎认为我正在执行 GET 而不是 POST:

 ["request.method", "GET"]

 ["error.message", "405 Method Not Allowed"]

关于我在这里可能做错了什么有什么建议吗?

更新:

我下载了 fiddler 并试图查看发生了什么,有趣的是,当我查看 header 时,它确实显示了 GET。这是我在 fiddler 中看到的屏幕截图:

enter image description here

我什至试图改变:

  client.Execute(request);

  client.Post(request);

但它仍然显示相同的内容。有什么想法吗?

最佳答案

事实证明这是网络服务器端的重定向问题,因此与 Rest Sharp 无关

我已要求删除问题以避免任何混淆。

关于c# - 使用 RestSharp 时,我在 POST 上收到 MethodNotFound 但响应认为它是 GET?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26018047/

相关文章:

c# - npgsql 和 Entity Framework 代码首先设置问题

c# - 使用 RestSharp 反序列化 JSON 时出现问题

java - Android 未找到changeBackground方法

c# - RestSharp 缺少执行功能?

c# - 如何将 JSON 反序列化为从 RestSharp 调用 API 返回的对象数组?

jquery - 为什么我会收到 Uncaught TypeError : Object #<an HTMLSelectElement> has no method 'find' ?

java - Camel 为存在且公开的方法抛出 MethodNotFound

c# - EF Core 查询在真实数据库中运行良好,但测试失败

c# - 如何扩展 String 类?

c# - 如何设置附件名称以在 Outlook 中正确显示