简体   繁体   English

如何使用Rest API在azure表中使用延续令牌

[英]How to use continuation tokens in azure table Using Rest API

Iam using .net Azure storage client library to retrieve data from server. Iam使用.net Azure存储客户端库从服务器检索数据。

My Entity contains more than 10000 records & it is retrieving 1000 records at once & giving response Headers x-ms-continuation-NextPartitionKey & x-ms-continuation-NextRowKey 我的实体包含超过10000条记录,并且一次检索1000条记录并给出响应标头x-ms-continuation-NextPartitionKey和x-ms-continuation-NextRowKey

I referred this 我提到了这个

https://docs.microsoft.com/en-us/rest/api/storageservices/Query-Entities?redirectedfrom=MSDN] https://docs.microsoft.com/en-us/rest/api/storageservices/Query-Entities?redirectedfrom=MSDN]

But did not understand how to use the those headers next time to get continuous records using Rest API 但不了解下一次如何使用这些标头使用Rest API获得连续记录

string storageAccount = "MyAccount";
string accessKey = "MYAccessKey";
string TableName = "TableName";
string uri = @"https://" + storageAccount + ".table.core.windows.net/" + TableName  + "?$top=100";
// Web request 
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = "GET";
request.ContentType = "application/json";
request.Accept = "application/json;odata=nometadata";
request.Headers["x-ms-date"] = DateTime.UtcNow.ToString("R", System.Globalization.CultureInfo.InvariantCulture);
request.Headers["x-ms-version"] = "2015-04-05";           
string stringToSign = request.Headers["x-ms-date"] + "\n";    
stringToSign += "/" + storageAccount + "/" + TableName;
System.Security.Cryptography.HMACSHA256 hasher = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String(accessKey));
string strAuthorization = "SharedKeyLite " + storageAccount + ":" + System.Convert.ToBase64String(hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(stringToSign)));


request.Headers["Authorization"] = strAuthorization;

Task<WebResponse> response = request.GetResponseAsync();
HttpWebResponse responseresult = (HttpWebResponse)response.Result;

You're really doing it the hard way, I mean, are you sure you want to manually write all requests? 我的意思是,您确实很难完成此操作,确定要手动编写所有请求吗? Looks very error prone to me. 看起来我很容易出错。 With the WindowsAzure.Storage NuGet Package, you get many function which wrap this for you. 使用WindowsAzure.Storage NuGet包,您可以获得许多将其包装起来的功能。 Using the Continuation Token is easy there: 在这里使用Continuation Token很容易:

Example copied from Microsoft Docs : Microsoft Docs复制的示例:

//List blobs to the console window, with paging.
Console.WriteLine("List blobs in pages:");

int i = 0;
BlobContinuationToken continuationToken = null;
BlobResultSegment resultSegment = null;

//Call ListBlobsSegmentedAsync and enumerate the result segment returned, while the continuation token is non-null.
//When the continuation token is null, the last page has been returned and execution can exit the loop.
do
{
    //This overload allows control of the page size. You can return all remaining results by passing null for the maxResults parameter,
    //or by calling a different overload.
    resultSegment = await container.ListBlobsSegmentedAsync("", true, BlobListingDetails.All, 10, continuationToken, null, null);
    if (resultSegment.Results.Count<IListBlobItem>() > 0) { Console.WriteLine("Page {0}:", ++i); }
    foreach (var blobItem in resultSegment.Results)
    {
        Console.WriteLine("\t{0}", blobItem.StorageUri.PrimaryUri);
    }
    Console.WriteLine();

    //Get the continuation token.
    continuationToken = resultSegment.ContinuationToken;
}
while (continuationToken != null);

We made great experience with those Microsoft NuGet Packages and highly recommend to use them. 我们在使用这些Microsoft NuGet软件包方面积累了丰富的经验,强烈建议使用它们。

如果要继续查询,请使用原始查询,但向请求添加参数-而不是标题以进行查询:

http://account.table....?query...&NextPartitionKey={value from x-ms-continuation-NextPartitionKey response header}&NextRowKey={value from x-ms-continuation-NextRowKey response header}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取 azure devops rest api 调用中所有测试运行的 azure 的延续令牌? - How to get continuation token for azure devops rest api calls in C# for fetching all test runs? 如何在.Net Core中使用REST API访问Azure表存储 - How to access azure table storage using REST API in .Net Core 使用REST API在Azure中创建表 - Create Table in Azure using REST API Azure表存储连续性 - Azure table Storage continuation 如何使用适用于.Net 2 C#的REST API为Azure表服务实现批处理启动 - How to implement a batch start for Azure table service using REST API for .Net 2 C# 如何使用Rest API C#更新JSON文件中的令牌 - How do I update tokens in a JSON file using Rest API C# Cosmo SQL Db-使用连续令牌查询数据永远不会完成 - Cosmo Sql Db - Querying data using continuation tokens never finishes 使用Rest API将数据插入到Azure表存储中时,将OData类型插入JSON负载的最佳方法 - The best way to insert odata type to json payload when use rest api insert data to azure table storage 如何使用访问令牌获取访问 REST API 的授权 - How to use access tokens to get authorization to access REST APIs 使用 Azure DevOps Rest API 重命名文件 - Renaming a file using Azure DevOps Rest API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM