我第一次使用RestSharp并执行POST,我有许多GET请求都可以正常工作。Rest Service在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"]
有什么建议我可能在这里做错了吗?
我下载了提琴手,试图查看发生了什么,当我看标题时,有趣的是,它确实显示了GET。这是我在提琴手中看到的屏幕截图:
我什至试图改变:
client.Execute(request);
到
client.Post(request);
但它仍然显示相同的内容。有任何想法吗?
原来这是Web服务器端的重定向问题,所以与Rest Sharp无关
我已要求删除该问题,以免造成任何混乱。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句