Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            button2.Text    = "执行中";
            string modulename = textBox4.Text.Trim();
            string action     = textBox5.Text.Trim();

            if (modulename.ToLower() == "pic" && action.ToLower() == "upload")
            {
                if (comboBox1.SelectedIndex == 1)
                {
                    MessageBox.Show("此接口不支持Get请求,切换成Post后重试");
                    button2.Text    = "执行";
                    button2.Enabled = true;
                    return;
                }
                using (OpenFileDialog of = new OpenFileDialog())
                {
                    of.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.gif";
                    if (of.ShowDialog() == DialogResult.OK)
                    {
                        string localfilename = of.FileName;
                        new Thread(() =>
                        {
                            string json = client.UploadFile(modulename, action, localfilename);
                            this.Invoke(new MethodInvoker(() =>
                            {
                                textBox1.Text   = json;
                                button2.Text    = "执行";
                                button2.Enabled = true;
                            }));
                        }).Start();
                    }
                    else
                    {
                        button2.Text    = "执行";
                        button2.Enabled = true;
                    }
                }
            }
            else
            {
                string data       = textBox6.Text.Trim();
                int    httpmethod = comboBox1.SelectedIndex;
                new Thread(() =>
                {
                    string json = client.DoAction(modulename, action, data, httpmethod);
                    this.Invoke(new MethodInvoker(() =>
                    {
                        textBox1.Text   = json;
                        button2.Text    = "执行";
                        button2.Enabled = true;
                    }));
                }).Start();
            }
        }