Created
July 31, 2015 00:43
-
-
Save dantheman213/5cd8f8373a5e65df737c to your computer and use it in GitHub Desktop.
C# HTTP GET request synchronous with additional header example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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