Tran Huy Quang

400 Bad Request - C#

Discussion created by Tran Huy Quang on Mar 11, 2018
Latest reply on Mar 12, 2018 by Vreddhi Bhat

I have a demo project that is used to call Diagnostic tools OPEN API to get the location of IP Address, but always got exception 400 Bad Request - The authorization header does not have the right format


const string client_token = "akab-***************";
const string access_token = "akab-xxxxxxxxxxxxxxxxxxx";
const string secret = "xxxxxxxxxxxxxxxxx";
const string api_url = "https://akab-************";

ClientCredential credentials = new ClientCredential(client_token, access_token, secret);
EdgeGridV1Signer signer = new EdgeGridV1Signer(null, 100000);

Uri uri = new Uri(api_url + "/diagnostic-tools/v2/ip-addresses/***.***.***.xx/geo-location");

WebRequest request = WebRequest.Create(uri);
request.Method = "GET";
//request.ContentType = "application/json";
ServicePointManager.Expect100Continue = false;
request.Credentials = new NetworkCredential("xxxxxxxx", "xxxxxxxxxxx");
request.PreAuthenticate = true;

// Signs the current request using the Akamai C# library. Creates an Authentication header for the request.
request = signer.Sign(request, credentials, null);

if (request is HttpWebRequest)
((HttpWebRequest)request).SendChunked = true;

   // Fails with 401 Signature doesn’t match
   var httpResponse = (WebResponse)request.GetResponse();
catch (WebException e)
   using (WebResponse response = e.Response)
      HttpWebResponse httpResponse = (HttpWebResponse)response;
      Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
      using (Stream data = response.GetResponseStream())
      using (var reader = new StreamReader(data))
         string text = reader.ReadToEnd();



Request Header:   

{Authorization: EG1-HMAC-SHA256 client_token=akab-xxxxxxxxxx-xxxxxxx;access_token=akab-xxxxx-******;timestamp=20180312T03:40:30+0000;nonce=c4ddb31d-4833-445b-a85a-6e177426a62c;signature=xxxxxxxxxxxxxxxxxxxxxxxxx



Can anyone help me to solve this problem?