用户系统; using system.collections.generic; using系统.component model; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Net; usingSystem.Text; usingSystem.Windows.Forms; namespaceTestProxy
{ publicpartialclassmainform : form }
{公共主信息()
{
} privatevoidbtndownload _ click (对象发送器,事件发生器() ) ) ) ) ) ) ) )。
{try{
开始(;
} Catch (执行Ex ) ) ) ) )。
{
messagebox.show(ex.message;
}
}私有语音开始(
{
txtResult.Clear (; var客户端=new webclient (; varuri=newuri(txturl.text.trim );
client .有趣的牛排=client _ downloadstringcompleted;
client.Encoding=Encoding.UTF8; if(checkbox.checked ) )。
{var proxy=CreateProxy (); if(proxy==null )返回;
client.Proxy=proxy;
}
client.downloadstringasync(uri;
} privatevoidclient _ downloadstringcompleted (对象发送器,downloadstringcompletedeventargs ) )。
{try{
txtResult.Text=e.Result;
} Catch (执行Ex ) ) ) ) )。
{var msg=ex.Message; if(ex.innerexception!=null ) msg=ex.InnerException.Message;
messagebox.show(msg;
}
} privatevoidcheckbox _ checked changed (object sender,EventArgs e ) ) ) ) ) ) ) )
{
GB proxy.enabled=checkbox.checked;
}隐私webproxy创建代理(
{var host=txtHost.Text.Trim (; if (string.isnullorwhitespace (host ) )
{
MessageBox.Show ('请输入代理地址); 返回空值;
}var port=0; try{
port=convert.toint 32 (txt port.text.trim ();
} catch (执行) ) ) ) )。
{
MessageBox.Show ('请输入正确的代理端口); 返回空值;
} var cre=newnetworkcredential (txtusername.text,txtPwd.Text ); var proxy=new webproxy (txt host.text.trim )、port ) {Credentials=cre}; 返回代理;
}
}
}