LoginSignup
0

posted at

WWW HTTPデータ取得 PROXY環境下

    /////////////////////////////////////////////////////////////
    // 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

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0