Created
November 28, 2018 17:16
-
-
Save filipnavara/076ffd9c54084b9b0c576cb61c89ee61 to your computer and use it in GitHub Desktop.
This file contains 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 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