Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void LoadPostFormDataAsync()
- {
- var values = new Dictionary<string, string>
- { { "comments", "Demo" },
- { "custemail", "example@example.com"},
- { "custname", "John Silver" },
- { "custtel", "+380991234567" },
- { "delivery", "11:00" },
- { "size", "medium"}
- };
- var stream = GetStreamAsync(RequestUri, values).Result;
- try
- {
- _document = new HTMLDocument(stream, RequestUri);
- Console.WriteLine(_document.Body.InnerHTML);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- private static async Task<Stream> GetStreamAsync(string requestUri, Dictionary<string, string> formData)
- {
- System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
- var content = new System.Net.Http.FormUrlEncodedContent(formData);
- var response = await client.PostAsync(requestUri, content);
- return await response.Content.ReadAsStreamAsync();
- }
- private static void LoadDocumentWithBasicAuth()
- {
- var requestMessage = new BasicAuthRequestMessage("user1", "passwd1", "https://httpbin.org/basic-auth/user1/passwd1");
- try
- {
- _document = new HTMLDocument(requestMessage);
- Console.WriteLine(_document.Body.InnerHTML);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement