Hello,
I have created a ASP.Net Core 2.0 API project.
When i run the api from postman , it works fine.
But when i tried to run from a WinForm application, it works only the Get and Post operations. DELETE, PUT and PATCH not working. Error comes is 'Method Not Allowed'.
I googled and tried to add these verbs in IIS's RequestFiltering. But still it persists.
Am running this in local machine. Can someone know how to resolve this, appreciated.
Here is my code snippet:-
private void cmdDelete_Click(object sender, EventArgs e)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://www.test.com/");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("Application/json"));
var uri = "api/customers/" + txtId.Text.Trim();
HttpResponseMessage response = client.DeleteAsync(uri).Result;
if (response.IsSuccessStatusCode)
{
MessageBox.Show ("Success");
}
else
MessageBox.Show ("Error : " + response.StatusCode + " : " + response.ReasonPhrase);
}
public async Task test()
{
Customer cust = new Customer();
int custId = Convert.ToInt32(txtId.Text);
await cust.DeleteCustomerDetails(custId);
}
NB : please note the API is working fine from Postman.
Regards
Jim
What I have tried:
I have googled and tried in IIS duly adding the httpverbs into the RequestFiltering. But that alone didnt work.