Example #1
0
        public static ResponseData PostFile(string Url, string File, CookieCollection Cookies, Encoding Encoding = null)
        {
            Encoding = Encoding ?? Encoding.Default;
            ResponseData result  = new ResponseData();
            var          request = (HttpWebRequest)WebRequest.Create(Url);

            request.CookieContainer = Cookies != null?Cookies.GetContainer() : null;

            request.Method      = "POST";
            request.ContentType = "application/octet-stream"; // binary data:
            request.Headers.Add("X-File-Name", System.IO.Path.GetFileName(File));

            // data (bytes) that will be posted in body of request
            Stream requestStream = request.GetRequestStream();
            Stream f             = System.IO.File.OpenRead(File);

            f.CopyTo(requestStream);
            f.Dispose();
            requestStream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            result.Cookies = HttpHelper.ReadCookies(response);

            Stream responseStream = response.GetResponseStream();

            result.BinaryContent = StreamHelper.ReadAllBytes(responseStream);
            result.TextContent   = Encoding.GetString(result.BinaryContent);
            result.Encoding      = Encoding;
            response.Close();

            return(result);
        }
Example #2
0
        public static ResponseData Get(string Url, CookieCollection Cookies, Encoding Encoding = null, string Referer = null, bool AllowAutoRedirect = true)
        {
            CookieContainer cc = Cookies.GetContainer();

            return(Get(Url, cc, Encoding, Referer, AllowAutoRedirect));
        }