Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created July 31, 2017 14:34
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 netsi1964/378e2e16b17836072c3b26992d53bd9c to your computer and use it in GitHub Desktop.
Save netsi1964/378e2e16b17836072c3b26992d53bd9c to your computer and use it in GitHub Desktop.
Make HEAD request to get content info as JSON
//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);
}
}
}
}
@netsi1964
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment