Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1.  
  2. public partial class Form1 : Form
  3. {
  4. private ICredentials credentials = new NetworkCredential();
  5.  
  6. private async void Get(string url)
  7. {
  8. using (var client = new WebClient())
  9. {
  10. client.Credentials = credentials;
  11. foreach (ListViewItem item in lstQuery.Items)
  12. {
  13. client.QueryString.Add(item.SubItems[0].Text, item.SubItems[1].Text);
  14. }
  15. try
  16. {
  17. var result = await client.DownloadStringTaskAsync(new Uri(url));
  18. txtOutput.Text = result;
  19. }
  20. catch (WebException e)
  21. {
  22. HandleException(e);
  23. }
  24. }
  25. }
  26.  
  27. private async void ExecuteMethod(string method, string url)
  28. {
  29. var values = new NameValueCollection();
  30. using (var client = new WebClient())
  31. {
  32. client.Credentials = credentials;
  33. foreach (ListViewItem item in lstQuery.Items)
  34. {
  35. values.Add(item.SubItems[0].Text, item.SubItems[1].Text);
  36. }
  37. try
  38. {
  39. var response = await client.UploadValuesTaskAsync(url, method, values);
  40. txtOutput.Text = Encoding.ASCII.GetString(response);
  41. }
  42. catch (WebException e)
  43. {
  44. HandleException(e);
  45. }
  46. }
  47. }
  48.  
  49. private void btnAdd_Click(object sender, EventArgs e)
  50. {
  51. var key = txtKey.Text;
  52. var value = txtValue.Text;
  53. lstQuery.Items.Add(new ListViewItem(new string[] { key, value }));
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement