Last active
October 29, 2020 14:54
-
-
Save Chibuikekenneth/5b9ebb75979a1ca0ed9e91cadda7885a to your computer and use it in GitHub Desktop.
webrequest-try-catch
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
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