我正在尝试使用 RestClient 进行删除操作,但我无法将我的 Json 对象包含在请求正文中。这是我的代码:
var client = new RestClient(WebService);
var request = new RestRequest(string.Format("/api/v1/{0}/{1}", controller, action), method);
request.AddHeader("Accept", ContentTypeApplicationJson);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", ContentTypeApplicationJson);
request.AddCookie(".ASPXAUTH", AspxAuth);
request.AddBody(jsonObjectRequest);
var response = client.Execute(request);
var jsonResponse = string.Empty;
using (var stream = new MemoryStream(response.RawBytes))
{
stream.Position = 0;
var sr = new StreamReader(stream);
jsonResponse = sr.ReadToEnd();
}
var jObjectDeserialize = GetJObjectDeserialize(jsonResponse);
在我的示例 ContentTypeApplicationJson = application/json 和 jsonObject 是一个对象,其中包含:
{ “BasketItemReferenceGuid”:“示例字符串 1”,“BasketReferenceGuid”:“示例字符串 2”}
这是我在提琴手的要求
删除 http://local.webapi.com/api/v1/BasketV3Products/ HTTP/1.1 接受:应用程序/json 内容类型:应用程序/json 用户代理:RestSharp 102.4.0.0 主机:local.webapi.com Cookie: .ASPXAUTH=E6D216034E2CB1A22466A501392B1E2E46601E345B8A0E7743D76CF2270ACFC8ED3C9F1F2F477C4499267222A250E4490291381EE68FE719E094EF1ACDD619B4D792341988F80CB67E8B5037D8ACF9FBABB74DE1E75A530AB432D85722D647771C6C576F8E810257CE9E60117DCEEFBD949EAD9E64C84898BDC5D691F957CE6266CF5652C693B86ED1D55907AAC5DC68 内容长度:0 接受编码:gzip,放气
谢谢