Created
July 31, 2017 14:34
-
-
Save netsi1964/378e2e16b17836072c3b26992d53bd9c to your computer and use it in GitHub Desktop.
Make HEAD request to get content info as JSON
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
//Rextester.Program.Main is the entry point for your code. Don't change it. | |
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 | |
using System; | |
using System.Net.Http; | |
namespace Rextester | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
HttpClient client = new HttpClient(); | |
var response = client.GetAsync("http://dr.dk").Result; | |
if (response.IsSuccessStatusCode) | |
{ | |
// by calling .Result you are performing a synchronous call | |
var responseContent = response.Content; | |
// by calling .Result you are synchronously reading the result | |
string responseString = responseContent.ReadAsStringAsync().Result; | |
var headers = response.Content.Headers; | |
string json = "{\"length\":"+headers.ContentLength+",\"type\":"+headers.ContentLength+"}"; | |
Console.WriteLine(json); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try it here: http://rextester.com/YBZ73344