【发布时间】:2020-09-15 07:38:31
【问题描述】:
我已付费订阅 Seeking Alpha,并拥有一个 cookie,可让我从 https://seekingalpha.com/symbol/AAPL/financials-data?period_type=quarterly&statement_type=income-statement&order_type=latest_left&is_pro=True 获取完整数据
我想使用 C# 收集 JSON 响应
下面是我可怕的代码
string cookie = "my super secret cookie string";
var request = new RestRequest(Method.GET);
request.AddHeader("content-type", "application/json");
request.AddHeader("Accept", "*/*");
request.AddHeader("User-Agent","Mozilla/5.0");
request.AddHeader("X-Requested-With", "XMLHttpRequest");
string url = "https://seekingalpha.com/symbol/AAPL/financials-data?period_type=quarterly&statement_type=income-statement&order_type=latest_left&is_pro=True";
request.AddParameter("cookie", cookie, ParameterType.Cookie);
var client = new RestClient(url);
var queryResult = client.Execute(request);
Console.WriteLine(queryResult.Content);
我怎样才能让它返回 JSON 给我?我得到了一些东西,但不是我想要的 JSON
【问题讨论】:
-
dotnetfiddle.net/jebgbn 这是一个
fiddle,其代码与您在question中发布的代码完全相同。您可以检查它是否返回json。奇怪的是,如果您尝试几次,它将开始在某些响应中返回html。然后再次返回json。 -
是的。我想我需要以某种方式进行身份验证。我有一个 cookie 字符串,只需要以某种方式传递它