Azure storage table REST Api call - Invalid Header


Azure storage table REST Api call - Invalid Header



I am trying to invoke the REST API to view the content of Azure Storage table.
Hope I have properly formed Authorization header value and I am getting below error. Please correct me where I am missing in below request (From REST Client app).


{
"method": "GET",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "https://#####.table.core.windows.net/testDB",
"headers": {
"x-ms-date": "Thu, 28 Jun 2018 08:39:05 GMT",
"x-ms-version": "2018-06-28",
"Accept": "application/json;odata=nometadata",
"Authorization": "SharedKeyLite #####:########"
},
"data": "",
"timeout": {}
}



And Here is my response Headers:


{
"x-ms-request-id": "3fc23b14-2002-0037-04bc-0e9e56000000",
"date": "Thu, 28 Jun 2018 08:46:39 GMT",
"server": "Microsoft-HTTPAPI/2.0",
"content-length": "371",
"content-type": "application/xml",
"status": 400
}



and Response Body


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>InvalidHeaderValue</code>
<message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.
RequestId:3fc23b14-2002-0037-04bc-0e9e56000000
Time:2018-06-28T08:46:40.1148690Z</message>
</error>



Here is the JAVA code, I used to generate SignatureString


private void printHash()
{
// https://mytestaccount.table.core.windows.net/testDB: this is the url form Azure portal displaying next to table
String secret = "I Updated my key here";
// Date for string to sign
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = sdf.format(calendar.getTime());
// canonicalizedResource, such as "/testaccount1/Tables"
String canonicalizedResource = "/testDB";
String stringToSign = date + "n" + canonicalizedResource;
System.out.println(stringToSign);
// HMAC-SHA@%^
Mac sha256HMAC = null;
try {
sha256HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
sha256HMAC.init(secretKey);
String hash = Base64.encodeToString(sha256HMAC.doFinal(stringToSign.getBytes()), Base64.DEFAULT);
System.out.println(hash);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
}





Please include the code for computing authorization header? Or are you simply copy the access key from portal and using that in authorization header?
– Gaurav Mantri
Jun 28 at 8:59





I have used JAVA code to generate authorization header
– Sai Prasad
Jun 28 at 9:03





please read the below artilcle i think this solve your query docs.microsoft.com/en-us/rest/api/storagerp/…
– Ankur Shah
Jun 28 at 9:05






I think value for your x-ms-version request header is incorrect. It should be 2018-03-28 instead of 2018-06-28.
– Gaurav Mantri
Jun 28 at 9:12


x-ms-version


2018-03-28


2018-06-28





I have removed the x-ms-version header, because its optional but no luck
– Sai Prasad
Jun 28 at 9:24




1 Answer
1



Four points to fix:


application/json;odata=nometadata


2013-08-15


2018-03-28


EEE, dd MMM yyyy HH:mm:ss 'GMT'


storageAccountNametableName


SecretKeySpec secretKey = new SecretKeySpec(Base64.decode(secret), "HmacSHA256");





Hi Jerry Liu, I appreciate your debug skill, It helped me lot to fix my issue. Still I am fail to get JSON response instead of XML.
– Sai Prasad
Jul 3 at 6:24





@SaiPrasad Could you offer some details about your error message?
– Jerry Liu
Jul 3 at 6:32





See my query in the post stackoverflow.com/questions/51148537/…
– Sai Prasad
Jul 3 at 7:10






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PHP contact form sending but not receiving emails

PHP parse/syntax errors; and how to solve them?

iOS Top Alignment constraint based on screen (superview) height