Skip to content

Instantly share code, notes, and snippets.

@filipnavara
Created November 28, 2018 17:16
Show Gist options
  • Save filipnavara/076ffd9c54084b9b0c576cb61c89ee61 to your computer and use it in GitHub Desktop.
Save filipnavara/076ffd9c54084b9b0c576cb61c89ee61 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Net;
using System.Reflection;
namespace WebExceptionTest
{
class MainClass
{
public static void Main(string[] args)
{
Type type = Type.GetType("Mono.Runtime");
if (type != null)
{
MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (displayName != null)
Console.WriteLine(displayName.Invoke(null, null));
}
var request = WebRequest.CreateHttp("https://www.googleapis.com/calendar/v3/users/me/calendarList");
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
request.Headers[HttpRequestHeader.Authorization] = "Bearer EXPIREDTOKEN";
try
{
request.GetResponse();
}
catch (WebException e)
{
string error;
using (var sr = new StreamReader(e.Response.GetResponseStream()))
error = sr.ReadToEnd();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment