C#状态200,响应中没有内容

问题描述 投票:1回答:1

我正在使用此C#代码:

httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var priceHistoryResponse = await _httpclient.GetAsync(priceHistoryUrlParameters);

if (priceHistoryResponse.StatusCode == HttpStatusCode.OK)
{
    // Put the post response in a string named priceHistoryResponseContent
    var priceHistoryResponseContent = await priceHistoryResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
    //  Convert the priceHistoryContent string to JSON format
    PriceHistory priceHistory = JsonConvert.DeserializeObject<PriceHistory>(priceHistoryResponseContent);
}

priceHistoryResponse为:

{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:{  Date: Sat, 01 Feb 2020 22:30:02 GMT  Connection: keep-alive  Host: api.tdameritrade.com  X-Forwarded-For: 10.152.4.23  X-Forwarded-Port: 9002  X-Forwarded-Proto: http  Authorization: Bearer roFzGtWR8xRppA7LlaZ280goscoXbGPwOfkxxxE  NS-Proxy-Client-IP: 99.11.242.43  thirdparty: true  Cache-Control: no-store, no-cache  Access-Control-Allow-Origin:   Access-Control-Allow-Headers: origin, x-requested-with, accept, authorization, content-type  Access-Control-Max-Age: 3628800  Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS, HEAD  Strict-Transport-Security: max-age=31536000  Content-Length: 0}}

此priceHistoryUrlParameters网址的格式是否正确?

https://api.tdameritrade.com/v1/marketdata/AAPL/pricehistory/apikey=AMN%40AMER.OAUTHAP

我添加了/apikey=AMN%40AMER.OAUTHAP

c# asp.net-core .net-core
1个回答
0
投票

我将/更改为? 。按照建议。现在可以使用。

© www.soinside.com 2019 - 2024. All rights reserved.