I'm trying to make a Delete action with RestClient but I'm not able to include my Json object inside the request body. This is my code:
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);
In my example ContentTypeApplicationJson = application/json and jsonObject is a object which contain:
{ "BasketItemReferenceGuid": "sample string 1", "BasketReferenceGuid": "sample string 2" }
This is my request in Fiddler
DELETE http://local.webapi.com/api/v1/BasketV3Products/ HTTP/1.1 Accept: application/json Content-Type: application/json User-Agent: RestSharp 102.4.0.0 Host: local.webapi.com Cookie: .ASPXAUTH=E6D216034E2CB1A22466A501392B1E2E46601E345B8A0E7743D76CF2270ACFC8ED3C9F1F2F477C4499267222A250E4490291381EE68FE719E094EF1ACDD619B4D792341988F80CB67E8B5037D8ACF9FBABB74DE1E75A530AB432D85722D647771C6C576F8E810257CE9E60117DCEEFBD949EAD9E64C84898BDC5D691F957CE6266CF5652C693B86ED1D55907AAC5DC68 Content-Length: 0 Accept-Encoding: gzip, deflate
Thanks