Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- private ICredentials credentials = new NetworkCredential();
- private async void Get(string url)
- {
- using (var client = new WebClient())
- {
- client.Credentials = credentials;
- foreach (ListViewItem item in lstQuery.Items)
- {
- client.QueryString.Add(item.SubItems[0].Text, item.SubItems[1].Text);
- }
- try
- {
- var result = await client.DownloadStringTaskAsync(new Uri(url));
- txtOutput.Text = result;
- }
- catch (WebException e)
- {
- HandleException(e);
- }
- }
- }
- private async void ExecuteMethod(string method, string url)
- {
- var values = new NameValueCollection();
- using (var client = new WebClient())
- {
- client.Credentials = credentials;
- foreach (ListViewItem item in lstQuery.Items)
- {
- values.Add(item.SubItems[0].Text, item.SubItems[1].Text);
- }
- try
- {
- var response = await client.UploadValuesTaskAsync(url, method, values);
- txtOutput.Text = Encoding.ASCII.GetString(response);
- }
- catch (WebException e)
- {
- HandleException(e);
- }
- }
- }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- var key = txtKey.Text;
- var value = txtValue.Text;
- lstQuery.Items.Add(new ListViewItem(new string[] { key, value }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement