I am new to API calls , I have written Create and Update methods which works fine but the DeleteAsync call which returns status 204 but not deleting the item. The request parameter is something like "FieldsOfBusiness/13158?Code=%27555%27"
. It works fine when replacing %27 with apostrophes in Postman
public async Task<bool> DeleteAsync<T>(object id, NameValueCollection parameters)
{
var queryString = ToQueryString(parameters);
HttpResponseMessage response = await Client.DeleteAsync($"{GetName<T>()}/{id}{queryString}")
.ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var a = await response.Content.ReadAsAsync<T>();
return response.IsSuccessStatusCode;
}
protected string ToQueryString(NameValueCollection nvc)
{
if (nvc == null || nvc.Count < 1)
return string.Empty;
var array = (from key in nvc.AllKeys
from value in nvc.GetValues(key)
select string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(value)))
.ToArray();
return "?" + string.Join("&", array);
}