Skip to content

Instantly share code, notes, and snippets.

@johndel
Created June 5, 2013 15:56
Show Gist options
  • Save johndel/5715019 to your computer and use it in GitHub Desktop.
Save johndel/5715019 to your computer and use it in GitHub Desktop.
C# check url response
// Response
try
{
using (var response = (HttpWebResponse)httpWReq.GetResponse() as HttpWebResponse)
{
if (httpWReq.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream())) {
string result = reader.ReadToEnd();
Microsoft.Win32.RegistryKey token;
token = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Cluey");
token.SetValue("Token", result);
token.Close();
System.Windows.Forms.MessageBox.Show("Successful login!");
System.Windows.Forms.Form.ActiveForm.Text = "Cluey Terminal";
//button1.Text = "Terminal Validation";
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
string error = reader.ReadToEnd();
System.Windows.Forms.MessageBox.Show(error);
System.Windows.Forms.Form.ActiveForm.Text = "Cluey Terminal";
//button1.Text = "Terminal Validation";
Console.WriteLine(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment