/ Published in: C#

Downloads contents as a byte array or string, depending on need.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
namespace VK.Snippets { using System.Collections.Generic; using System.IO; using System.Net; using System.Text; public static class HttpFetcher { public static string FetchPage(string url, string username = "", string password = "", string domain = "") { string page = Encoding.ASCII.GetString(FetchContent(url, username, password, domain)); return page; } public static byte[] FetchContent(string url, string username = "", string password = "", string domain = "") { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); if (username != "" && password != "" && domain != "") { } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream responseStream = response.GetResponseStream(); int b; while ((b = responseStream.ReadByte()) != -1) { contentBytes.Add((byte)b); } } return contentBytes.ToArray(); } } }
Comments
