/////////////////////////////////////////////////////////////
// WWW HTTPデータ取得 PROXY環境下
/////////////////////////////////////////////////////////////
private async void button3_Click(object sender, EventArgs e) {
textBox1.Text="";
HttpClientHandler ch = new HttpClientHandler();
ch.Proxy = new WebProxy("http://xxxxxx:8080");
ch.Proxy.Credentials = new NetworkCredential("usr", "passwd");
ch.UseProxy = true;
HttpClient client = new HttpClient(ch);
await Task.Run(() =>{
try{
var task = client.GetStringAsync("https://www.yahoo.co.jp/");
task.Wait();
this.Invoke((Action)(() => {
textBox1.Text = task.Result;
}));
}
catch (Exception ex){
this.Invoke((Action)(() => {
textBox1.Text = ex.GetBaseException().ToString();
}));
}
});
}
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
0