AsyncTask到Azure - 服务器无法验证请求

时间:2016-10-06 12:06:50

标签: java android azure

try
    {
        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.getContainerReference("config");

        // Loop through each blob item in the container.
        // If the item is a blob, not a virtual directory.
        for (ListBlobItem blobItem : container.listBlobs()) {
            if (blobItem instanceof CloudBlob) {
                // Download the item and save it to a file with the same name.
                CloudBlob blob = (CloudBlob) blobItem;
                if(blob.getName().equalsIgnoreCase(configFileName)) {
                    blob.download(new java.io.FileOutputStream(HashOutConfig.ROOT_PATH + "/" + configFileName));
                    return HashOutConfig.ROOT_PATH + "/" + configFileName;
                }
            }
        }
        return null;
    }
    catch (Throwable th)
    {
        // Output the stack trace.
        th.printStackTrace();
        Log.e(TAG,"Exception==>>>",th);
        Log.e(TAG,"Error while dowloading file from blob storage"+th.getMessage().toString());
        return null;
    }
10-06 12:16:26.312 4491-5605/com.microsoft.hashout W/System.err: java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.
10-06 12:16:26.312 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113)
10-06 12:16:26.313 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.hashout.task.DownloadFromBlobStorage.downloadFromAzureBlobStorage(DownloadFromBlobStorage.java:68)
10-06 12:16:26.313 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.hashout.task.DownloadFromBlobStorage.doInBackground(DownloadFromBlobStorage.java:38)
10-06 12:16:26.313 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.hashout.task.DownloadFromBlobStorage.doInBackground(DownloadFromBlobStorage.java:20)
10-06 12:16:26.317 4491-5605/com.microsoft.hashout W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
10-06 12:16:26.317 4491-5605/com.microsoft.hashout W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-06 12:16:26.317 4491-5605/com.microsoft.hashout W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
10-06 12:16:26.318 4491-5605/com.microsoft.hashout W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
10-06 12:16:26.318 4491-5605/com.microsoft.hashout W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
10-06 12:16:26.318 4491-5605/com.microsoft.hashout W/System.err:     at java.lang.Thread.run(Thread.java:818)
10-06 12:16:26.318 4491-5605/com.microsoft.hashout W/System.err: Caused by: com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
10-06 12:16:26.319 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
10-06 12:16:26.319 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175)
10-06 12:16:26.319 4491-5605/com.microsoft.hashout W/System.err:     at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:109)
10-06 12:16:26.320 4491-5605/com.microsoft.hashout W/System.err:    ... 9 more

2 个答案:

答案 0 :(得分:1)

Caused by: com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

错误的凭证可能吗?

答案 1 :(得分:0)

根据我的经验,这个问题可能是由于storageConnectionString造成的。 您可以检查是否复制了正确的帐户密钥。

希望它有所帮助。如有任何疑虑,请随时告诉我。