惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
博客园 - 【当耐特】
量子位
有赞技术团队
有赞技术团队
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
C
Check Point Blog
B
Blog RSS Feed
M
MIT News - Artificial intelligence
H
Help Net Security
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
腾讯CDC

博客园 - Gofficer

决战紫禁之巅 为学 C#网页自动登录和提交POST信息的多种方法 一个C#写的调用外部进程类 快速实现在Windows应用程序中支持拖拽的TreeView控件(C#) PPT转图片 开发人员,敢问路在何方? C# 实现注销、关机、重启电脑功能 ultraGrid 控件中,实现单元格内容换行显示 如何用一条sql取得第10到第20条的记录? 用Sandcastle一键生成CHM帮助文档 实现服务器端与客户端对话 C#中访问WEB页面 自定义Ping方法 HTTP请求和应答 Socket套接字实现服务器端连接 Socket套接字实现客户端连接 启动和停止本地系统进程 异常处理
使用代理服务器
Gofficer · 2007-08-24 · via 博客园 - Gofficer

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
// 添加新的命名空间。
using System.Net;
using System.IO;

namespace Proxy
{
    
/// <summary>
    
/// 使用代理服务器。
    
/// </summary>

    public class Form1 : System.Windows.Forms.Form
    
{
        
private System.Windows.Forms.Button button1;
        
private System.Windows.Forms.Button button2;
        
private System.Windows.Forms.RichTextBox richTextBox1;
        
/// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
public Form1()
        
{
            
//
            
// Windows 窗体设计器支持所必需的
            
//
            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            
//
        }


        
/// <summary>
        
/// 清理所有正在使用的资源。
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if (components != null)
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }


        
Windows Form Designer generated code

        
/// <summary>
        
/// 应用程序的主入口点。
        
/// </summary>

        [STAThread]
        
static void Main()
        
{
            Application.Run(
new Form1());
        }

        
// 定义私有变量。
        public HttpWebRequest req;
        
public HttpWebResponse res;
        
public WebProxy proxy;
        
public Stream s;
        
public StreamReader r;
        
// 使用默认代理。
        private void button1_Click(object sender, System.EventArgs e)
        
{
            button1.Enabled 
= false;
            proxy 
= new WebProxy("http://127.0.0.1:8888"true);
            GlobalProxySelection.Select 
= proxy;
            req 
= (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
            res 
= (HttpWebResponse)req.GetResponse();
            s 
= res.GetResponseStream();
            r 
= new StreamReader(s);
            richTextBox1.Text 
= r.ReadToEnd();
            r.Close();
            s.Close();
            res.Close();
            button1.Enabled 
= true;
        }

        
// 使用专门代理。
        private void button2_Click(object sender, System.EventArgs e)
        
{
            button2.Enabled 
= false;
            proxy 
= new WebProxy("http://127.0.0.1:8887"true);
            req 
= (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
            req.Proxy 
= proxy;
            res 
= (HttpWebResponse)req.GetResponse();
            s 
= res.GetResponseStream();
            r 
= new StreamReader(s);
            richTextBox1.Text 
= r.ReadToEnd();
            r.Close();
            s.Close();
            res.Close();
            button2.Enabled 
= true;
        }

    }

}