Skip to content

Instantly share code, notes, and snippets.

@Chibuikekenneth
Last active October 29, 2020 14:54
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 Chibuikekenneth/5b9ebb75979a1ca0ed9e91cadda7885a to your computer and use it in GitHub Desktop.
Save Chibuikekenneth/5b9ebb75979a1ca0ed9e91cadda7885a to your computer and use it in GitHub Desktop.
webrequest-try-catch
try
{
WebResponse response = await request.GetResponseAsync();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string responseContent = reader.ReadToEnd();
JObject adResponse =
Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(responseContent);
return adResponse;
}
}
catch (WebException webException)
{
if (webException.Response != null)
{
using (StreamReader reader = new StreamReader(webException.Response.GetResponseStream()))
{
string responseContent = reader.ReadToEnd();
return Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(responseContent); ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment