如何使用c#从网站捕获Json

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

我订阅了Seeking Alpha,并有一个Cookkie,使我能够从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

c# rest restsharp
1个回答
0
投票
尝试将您的Access标头更新为application/json

request.AddHeader("Accept", "application/json");

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