我正在使用 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 中看到的屏幕截图:
我什至试图改变:
client.Execute(request);
到
client.Post(request);
但它仍然显示相同的内容。有什么想法吗?
最佳答案
事实证明这是网络服务器端的重定向问题,因此与 Rest Sharp 无关
我已要求删除问题以避免任何混淆。
关于c# - 使用 RestSharp 时,我在 POST 上收到 MethodNotFound 但响应认为它是 GET?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26018047/