繁体   English   中英

Microsoft 价目表 api 出现损坏。 返回部分响应

[英]Microsoft rate card api appears broken. Returning partial response

我正在尝试通过访问 management.azure.com api 来获取我的订阅的定价详细信息。 根据此处的文档: https://docs.microsoft.com/en-us/previous-versions/azure/reference/mt219004(v=azure.100)?redirectedfrom=MSDN

我尝试使用提供的代码 API、Postman 和第三方库( https://github.com/codehollow/AzureBillingApi/这一切都无法消除不良响应)。

原型代码如下:

AzureCredentials credentials = credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
                clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud).WithDefaultSubscription(subscriptionId);

ServiceClientCredentials serviceClientCredentials = await await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);

string urlString = @$"https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Commerce/RateCard?api-version=2016-08-31-preview&$filter=OfferDurableId eq 'MS-AZR-0003p' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US' and MeterCategory eq 'Storage'";

using (HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, urlString))
{
     await serviceClientCredentials.ProcessHttpRequestAsync(requestMessage, CancellationToken.None);

     using (HttpClient client = new HttpClient())
     {
          HttpResponseMessage responseMessage = await client.SendAsync(requestMessage);

          if(!responseMessage.IsSuccessStatusCode)
               throw new InvalidOperationException(responseMessage.ReasonPhrase);

          string contentString = await responseMessage.Content.ReadAsStringAsync();
          RateCardResponse rateCardResponse =   JsonConvert.DeserializeObject<RateCardResponse>(contentString);
     }
}

虽然我得到一个有效的响应 (200),但 contentString 变量是无效的 JSON。 为了便于阅读,示例已被缩短。

{
    "OfferTerms": [],
    "Meters": [
        {
            "EffectiveDate": "2020-05-01T00:00:00Z",
            "IncludedQuantity": 0.0,
            "MeterCategory": "Virtual Machines",
            "MeterId": "cd2d7ca5-2d4c-5f93-94d0-8cee0662c71c",
            "MeterName": "E20 v4",
            "MeterRates": {
                "0": 1.52
            },
            "MeterRegion": "AP Southeast",
            "MeterStatus": "Active",
            "MeterSubCategory": "Ev4 Series",
            "MeterTags": [],
            "Unit": "1 Hour"
        },
        {
            "EffectiveDate": "2020-11-01T00:00:00Z",
            "IncludedQuantity": 0.0,
            "MeterCategory": "Virtual Machines Licenses",
            "MeterId": "e8ceef66-d651-5a3c-9af9-046917e3a466",
            "MeterName": "104 vCPU License",
            "MeterRates": {
                "0": 1.456
            },
            "MeterRegion": <ACTUAL RESPONSE IS 627,746 bytes but always cuts off at this point>

这个网站( https://azureprice.net/ )似乎从同一个 API 中提取最近的细节没有问题,但我很难过为什么我的回复被切断和无效。

我只是再次运行该代码,无论是否使用 stream 阅读器,它都可以正常工作。 我猜微软的人遇到了问题并纠正了它。 仍然没有过滤能力,但我可以做那个客户端。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM