C # using Httpwebrequest,httpwebresponse to quickly verify that proxy IP is useful

Source: Internet
Author: User
Tags port number

Everyone good, I believe that we have used proxy IP over the network, but some IP one or two days expired. To one of the manual to try to open ie, shut down IE, how annoying ah.

It would be nice to have this article. We can use Httpwebrequest,httpwebresponse to proxy verification, thank you for your comment guide!

Oh, is not very simple ah, in fact, this section of the code can also do a collector, thieves and other procedures! I'm not telling you, everybody, look.

public void Yanzhen (string str, int port)
{
WebProxy proxyobject = new WebProxy (str, port);//str for IP address port port number
HttpWebRequest Req = (HttpWebRequest) webrequest.create ("http://www.whatismyip.com.tw/");
Req.proxy = Proxyobject; Set up agents
Reprint please indicate from the problem solving Park http://wenti.cnblogs.com/
Article address
HttpWebResponse Resp = (HttpWebResponse) req.getresponse ();
String str = "";
String okstr = "";
Encoding code = encoding.getencoding ("UTF-8");
using (StreamReader sr = new StreamReader (Resp.getresponsestream (), code))
{
if (SR!= null)
{
Try
{
str = Sr. ReadToEnd ();
Stringsub.substr (str, "str = str. Substring (str. IndexOf (start) + start. Length);
Okstr = str. Substring (0, str. IndexOf (last));
MessageBox.Show ("Verify success!") Display IP as "+ okstr";
}
Catch
{
MessageBox.Show ("file read failed!") ");
}
Finally
{
Sr. Close ();
}
}
}
}

Oh, is not very simple ah, in fact, this section of the code can also do a collector, thieves and other procedures!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.