Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An example of GET request using HttpClient in C#
namespace API.Controllers
public class GithubController : ApiController
private const string _address = "";
private const string _userAgent = "TestApp";
// GET api/<controller>
public async Task<string> Get()
var result = await GetAsync(_address);
return result.ToString();
private async Task<JObject> GetAsync(string uri)
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "token ADD YOUR OAUTH TOKEN");
client.DefaultRequestHeaders.Add("User-Agent", _userAgent);
var content = await client.GetStringAsync(uri);
return JObject.Parse(content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment