© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
James213

❔ Unable to make a GET request

I get a 403 - "Forbidden" from this code. I have successfully tested (200) with Postman and a Python version.
Here is the doc fyi https://docs.github.com/en/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-the-authenticated-user

  // Create an HttpClient object (pass into function)
  HttpClient client = new();

...


       public async Task<HttpResponseMessage> GetResponse(string apiKey, string url, HttpClient client)
        {
            /* 
            Contents
            1. Headers for the request
            2. Return the response from the API using the HttpClient object
            */

            // 1. Headers for the request
            Dictionary<string, string> headers = new()
            {
                { "Accept", "application/vnd.github+json" },
                { "Authorization", $"Bearer {apiKey}" },
                { "X-GitHub-Api-Version", "2022-11-28" }
            };

            // 2. Return the response from the API using the HttpClient object
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
            foreach (var header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            HttpResponseMessage response =  await client.SendAsync(request);

            return response;

        }
  // Create an HttpClient object (pass into function)
  HttpClient client = new();

...


       public async Task<HttpResponseMessage> GetResponse(string apiKey, string url, HttpClient client)
        {
            /* 
            Contents
            1. Headers for the request
            2. Return the response from the API using the HttpClient object
            */

            // 1. Headers for the request
            Dictionary<string, string> headers = new()
            {
                { "Accept", "application/vnd.github+json" },
                { "Authorization", $"Bearer {apiKey}" },
                { "X-GitHub-Api-Version", "2022-11-28" }
            };

            // 2. Return the response from the API using the HttpClient object
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
            foreach (var header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            HttpResponseMessage response =  await client.SendAsync(request);

            return response;

        }
GitHub Docs
Gists - GitHub Docs
Gists - GitHub Docs
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How to get specific fields from a Http GET request
C#CC# / help
3y ago
Deployed Refit implementation turns POST request into a GET request?
C#CC# / help
2mo ago
Unable to get localization to get to work in MVC .net8
C#CC# / help
2y ago
What's better to get in request?
C#CC# / help
4y ago