Advertisement
andruhovski

Post v.17.12

Jan 23rd, 2018
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. private static void LoadPostFormDataAsync()
  2. {
  3. var values = new Dictionary<string, string>
  4. { { "comments", "Demo" },
  5. { "custemail", "example@example.com"},
  6. { "custname", "John Silver" },
  7. { "custtel", "+380991234567" },
  8. { "delivery", "11:00" },
  9. { "size", "medium"}
  10. };
  11.  
  12. var stream = GetStreamAsync(RequestUri, values).Result;
  13. try
  14. {
  15. _document = new HTMLDocument(stream, RequestUri);
  16. Console.WriteLine(_document.Body.InnerHTML);
  17. }
  18. catch (Exception e)
  19. {
  20. Console.WriteLine(e.Message);
  21. }
  22. }
  23.  
  24. private static async Task<Stream> GetStreamAsync(string requestUri, Dictionary<string, string> formData)
  25. {
  26. System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
  27. var content = new System.Net.Http.FormUrlEncodedContent(formData);
  28. var response = await client.PostAsync(requestUri, content);
  29. return await response.Content.ReadAsStreamAsync();
  30. }
  31.  
  32. private static void LoadDocumentWithBasicAuth()
  33. {
  34. var requestMessage = new BasicAuthRequestMessage("user1", "passwd1", "https://httpbin.org/basic-auth/user1/passwd1");
  35. try
  36. {
  37. _document = new HTMLDocument(requestMessage);
  38. Console.WriteLine(_document.Body.InnerHTML);
  39. }
  40. catch (Exception e)
  41. {
  42. Console.WriteLine(e.Message);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement