Reputation: 21
I am using Azure storage rest apis in a java program and trying to create a pageblob and then upload a vhd using put page.
Here is my code:
url = String.format("https://myaccount.blob.core.windows.net/vhds/mypageblob");
Date now = new Date();
SimpleDateFormat dateFormatter = new SimpleDateFormat("E, dd MMM yyyy hh:mm:ss zzz");
dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
requestHeaders.put( "x-ms-date", dateFormatter.format(now));
requestHeaders.put( "x-ms-blob-type", "PageBlob");
requestHeaders.put("x-ms-blob-content-length", "4096");
requestHeaders.put("x-ms-blob-sequence-number", "0");
requestHeaders.put("Authorization", "SharedKey");
// Use api to get the shared key.
requestHeaders.put("myaccount", primary_key);
I get an error 'The value for one of the HTTP headers is not in the correct format. 400'. Any idea how i can debug this?
Upvotes: 0
Views: 456
Reputation: 576
I would say that the ideal option here is to use the Azure Storage Java Client Library, available through Maven or GitHub (as source).
If that's not possible and for some reason you need to use the REST API's directly, it may still be useful to look through the source code for the library, to see how we implement the required logic.
As for the above code, it looks like you are splitting the auth-related information into two separate headers. It should be one header, something like this:
Authorization: SharedKey myaccount:ctzMq410TV3wS7upTBcunJTDLEJwMAZuFPfr0mrrA08=
Also, are you transferring your storage primary key directly? This isn't the way authentication works, you need to use the key to sign a specific "Signature String" that identifies the request. See https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx for full documentation of how to authenticate to Azure Storage.
Upvotes: 1