这是我在邮递员中的要求。它正在发挥作用。
我正在尝试使用RestSharp做同样的事情。我的方法:
public bool CloseVisit(int visitDateId)
{
try
{
bool result = true;
var request = new RestRequest();
request.Method = Method.PUT;
request.Resource = Const.CloseVisitUrl + visitDateId.ToString();
request.AddHeader("Content-Type", "text/plain");
Parameter p = new Parameter();
p.Name = "text/plain";
p.Type = ParameterType.RequestBody;
p.ContentType = "text/plain";
p.Value = sessionId;
request.AddParameter(p);
var response = client.ExecuteAsync(request);
if (response.Result.StatusCode == System.Net.HttpStatusCode.OK)
{
result = true;
}
else
return false;
return result;
}
catch (Exception ex)
{
return false;
}
}
但我收到了内部错误。谢谢你的帮助。
答案 0 :(得分:0)
这是一个简单的例子:
var client = new RestClient("https://example.com/api");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer xyz");
request.AddHeader("Content-Type", "text/plain");
request.AddParameter("text/plain", "Hello World!", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);