自学内容网 自学内容网

C# 代理IP的winform

C# 代理IP的winform


using System;
using System.Net;
using System.Windows.Forms;
 
namespace ProxyIPWinForms
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
 
        private void btnSendRequest_Click(object sender, EventArgs e)
        {
            string proxyAddress = $"http://{txtProxyIP.Text}:{txtProxyPort.Text}";
            WebProxy proxy = new WebProxy(proxyAddress);
 
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://example.com");
            request.Proxy = proxy;
 
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                MessageBox.Show($"Status Code: {response.StatusCode}");
                response.Close();
            }
            catch (WebException ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }
    }
}

原文地址:https://blog.csdn.net/weixin_43050480/article/details/144412535

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!