1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
private: System::Void Button2_Click(System::Object^ sender, System::EventArgs^ e) {
if (Username->Text == "" && Password->Text == "")
{
timer1->Interval = 10000;
timer1->Start();
}
else
{
if (GetHTMLPage("http://www.whatismyip.com" +
ProxyAddress->Text, AutomaticServer->Checked,
ProxyAddress->Text,
((Microsoft::VisualBasic::Information::IsNumeric(ProxyPorts->Text)),
ProxyPorts->Text = 0), Username->Text, Password->Text) == "")
{
IPAddress->Text = IPAddress->Text;
}
else
{
IPAddress->Text = ProxyAddress->Text;
}
}
}
public:
String ^GetHTMLPage(String ^URL, bool UseProxy, String ^ProxyAddress, int ProxyPort, String ^UserName, String ^PassWord)
{
return GetHTMLPage(URL, UseProxy, ProxyAddress, ProxyPort, UserName, PassWord, "");
}
public:
String ^GetHTMLPage(String ^URL, bool UseProxy, String ^ProxyAddress, int ProxyPort, String ^UserName)
{
return GetHTMLPage(URL, UseProxy, ProxyAddress, ProxyPort, UserName, "", "");
}
public:
String ^GetHTMLPage(String ^URL, bool UseProxy, String ^ProxyAddress, int ProxyPort)
{
return GetHTMLPage(URL, UseProxy, ProxyAddress, ProxyPort, "", "", "");
}
public:
String ^GetHTMLPage(String ^URL, bool UseProxy, String ^ProxyAddress)
{
return GetHTMLPage(URL, UseProxy, ProxyAddress, 0, "", "", "");
}
public:
String ^GetHTMLPage(String ^URL, bool UseProxy)
{
return GetHTMLPage(URL, UseProxy, "", 0, "", "", "");
}
public:
String ^GetHTMLPage(String ^URL)
{
return GetHTMLPage(URL, false, "", 0, "", "", "");
}
public:
String ^GetHTMLPage(String ^URL, bool UseProxy, String ^ProxyAddress, int ProxyPort, String ^UserName, String ^PassWord, String ^Domain)
{
String ^sResult = "";
try
{
WebResponse ^objResponse = nullptr;
WebRequest ^objRequest = System::Net::HttpWebRequest::Create(URL);
if (! UseProxy)
{
WebProxy ^oProxy = gcnew WebProxy(ProxyAddress, ProxyPort);
if (Domain != "")
{
oProxy->Credentials = gcnew NetworkCredential(UserName, PassWord, Domain);
}
else
{
oProxy->Credentials = gcnew NetworkCredential(UserName, PassWord);
}
objRequest->Proxy = oProxy;
}
objRequest->Method = "GET";
objRequest->Timeout = 120000; // 20 sec.
objResponse = objRequest->GetResponse();
System::IO::StreamReader ^sr = gcnew System::IO::StreamReader(objResponse->GetResponseStream(), System::Text::Encoding::UTF7);
sResult = sr->ReadToEnd();
sr->Close();
// when code-execution has reached this point without
// throwing an error, the html page is loaded which
// means all is o.k.
MessageBox::Show("You are connected Success");
}
catch (System::Exception ^ex)
{
MessageBox::Show("You have failed connected");
}
return sResult;
}
|