Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Created July 31, 2015 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantheman213/5cd8f8373a5e65df737c to your computer and use it in GitHub Desktop.
Save dantheman213/5cd8f8373a5e65df737c to your computer and use it in GitHub Desktop.
C# HTTP GET request synchronous with additional header example
using (var client = new HttpClient())
{
var request = new HttpRequestMessage()
{
RequestUri = new Uri("http://google.com/"),
Method = HttpMethod.Get
};
request.Headers.Add("Content-Type", "application/json; charset=utf-8");
var response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
string data = responseContent.ReadAsStringAsync().Result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment