Page 1 of 1

YAHOO FINANCE ERROR FOR C#

Posted: Thu May 30, 2024 3:38 pm
by admin
Yahoo finance provides unofficial api to extract fianancial data. But fetching these data user has to GET access through browser.
Earlier using C# httpclient data extraction and calculation was easy. But recent restriction in header by yahoo finance resulted error in c# coders.
There is a solution to make it work by adding header to your httpclient properties.
1. Declare httpclient

Code: Select all

var httpClient = new HttpClient();
2. Define default header for httpclient

Code: Select all

httpClient.DefaultRequestHeaders.Add("User-Agent",
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0");

Adding user-agent in header file of httpclient request yahoo finance restrictions can be eliminated.


Thanks
Admin