AnsweredAssumed Answered

415 even though I submit with application/json

Question asked by Stepan Kozak on Dec 9, 2015
Latest reply on Dec 17, 2015 by Laurence Leccia

Hi I'm trying to use Akamai Purge API https://api.ccu.akamai.com/ccu/v2/queues/default endpoint through C# code. I'm sending POST request using following code (which is based on the sample code from here https://jsapi.apiary.io/apis/akamaiopen2purgeccuproduction/reference/request-queues/ccuv2queuesqueuename/add-a-request.h…). Unfortunatelly, I'm getting always 415 Expected an entity of content type application/json, text/javascript. Even though I'm sending the POST request with applicaiton/json content-type. Can anybody tell me what I'm doing wrong? Thanks.

 

this.httpClient = new HttpClient { BaseAddress = new Uri("https://api.ccu.akamai.com/ccu/v2/") };

this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authorizationHeader);

this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

 

using (StringContent content = new StringContent(this.CreateJsonPayload(), Encoding.UTF8, "application/json"))

{

  using (HttpResponseMessage response = this.httpClient.PostAsync("queues/default", content).Result)

  {

  string reponseString = response.Content.ReadAsStringAsync().Result;

  Dictionary<string, string> result =

  JsonConvert.DeserializeObject<Dictionary<string, string>>(reponseString);

 

  // Here I always get 415 status "Expected an entity of content type application/json, text/javascript"

  }

}

 

 

private string CreateJsonPayload()

{

  const string BasePayload = "{{ 'objects' : [ {0} ] }}";

  string[] urlsToFlush = this.txtUrls.Text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

  return string.Format(BasePayload, string.Join(", ", urlsToFlush.Select(x => string.Concat("'", x.Trim(), "'"))));

}

Outcomes