我第一次使用 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 并试图看看发生了什么,有趣的是,当我查看标题时,它确实显示了一个 GET。这是我在提琴手中看到的屏幕截图:
我什至试图改变:
client.Execute(request);
至
client.Post(request);
但它仍然显示相同的东西。有任何想法吗?