Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status Code 403:Forbidden - Solution #50

Open
poynty opened this issue Apr 19, 2023 · 1 comment
Open

Status Code 403:Forbidden - Solution #50

poynty opened this issue Apr 19, 2023 · 1 comment

Comments

@poynty
Copy link

poynty commented Apr 19, 2023

For the past few months using the default implementations of the clients in this library has resulted in HTTP status codes of 403. The reason is that CoinGecko now require a user agent specified in the requests.

This library already provides the fix built in you just have to use it!

If we look at the BaseAPIClient in the library we see this at line 43:

//_httpClient.DefaultRequestHeaders.Add("User-Agent", "your bot 0.1");

Each client in this library provides the ability to pass in your own instance of System.Net.HttpClient which is great because you can make one and set a DefaultRequestHeader of User-Agent.

So for example:

//Create an instance of System.Net.HttpClient and add our request header
HttpClient hClient = new HttpClient();
hClient.DefaultRequestHeaders.Add("User-Agent","myApp or whatever");

//Pass our HttpClient instance to the CoinCecko client
ICoinGeckoClient cgClient = new CoinGeckoClient(hClient);

Hopefully this helps anyone getting this problem.

@OxfordGrid
Copy link

Thanks mate! Worked like a charm for me.

@tosunthex should it be added to Readme to help anyone who will suffer with it in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants