Created
June 5, 2013 15:56
-
-
Save johndel/5715019 to your computer and use it in GitHub Desktop.
C# check url response
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
// 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