Click here to Skip to main content
15,884,038 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public HttpResponseMessage Delete(string strApiKey)
{
  string strDomainName = PageUtility.GetCurrentDomainName();
  HttpClient client = new HttpClient();
  client.BaseAddress = new Uri(strDomainName);

  // Add an Accept header for JSON format.
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  HttpResponseMessage response = client.DeleteAsync(strApiKey).Result;  // Blocking call!
  return response;
}


response shows error as given below

C#
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  X-SourceFiles: =?UTF-8?B?RDpcU2F0eWVuZHJhXERldmVsb3BlbWVudFxUZXN0QXBpXFRlc3RBcGlcYXBpXFRlc3RcMw==?=
  Cache-Control: private
  Date: Tue, 25 Nov 2014 10:31:10 GMT
  Server: Microsoft-IIS/8.0
  X-Powered-By: ASP.NET
  Content-Length: 4917
  Content-Type: text/html; charset=utf-8
}}
Posted
Updated 24-Nov-14 23:37pm
v3
Comments
Nathan Minier 25-Nov-14 7:12am    
Looks like you're calling an async process in a sync manner, which is likely what's causing your issue.

Have you tried awaiting the client.DeleteAsync()?
itsathere 25-Nov-14 7:25am    
HttpResponseMessage response = await client.DeleteAsync(strApiKey).Result;

r u saying the about above code
Nathan Minier 25-Nov-14 7:43am    
That won't work. Do you want your function to be async or sync using an async resource?

Also, why are you sending a web request to a local resource?
Nathan Minier 25-Nov-14 7:45am    
Also, have you evaluated the output of PageUtility.GetCurrentDomainName()?
itsathere 25-Nov-14 7:58am    
i m sending web request to controller..actually i m able to add and edit using api controller but unable to delete or update..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900