Exemplo n.º 1
0
        /// <summary>
        ///     Gets all type request data.
        /// </summary>
        /// <param name="parm"></param>
        /// <param name="postParamDict"></param>
        /// <returns></returns>
        public static string GetRequestResult(this ResponseParam parm, IDictionary <string, string> postParamDict = null)
        {
            if (parm is null)
            {
                throw new ArgumentNullException(nameof(parm));
            }

            var postData = string.Empty;

            if (postParamDict != null)
            {
                postData = CreateParameter(postParamDict);
            }

            var response = parm.CreateHttpResponse(postData);

            var stream = response.GetResponseStream();

            if (stream is null)
            {
                throw new NullReferenceException(nameof(stream));
            }

            using (var reader = new StreamReader(stream, parm.EncodeType))
                return(reader.ReadToEnd());
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Uploads the file.
        /// </summary>
        /// <param name="parm"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string UploadFile(this ResponseParam parm, FileSystemInfo filePath = null)
        {
            if (parm is null)
            {
                throw new ArgumentNullException(nameof(parm));
            }

            var response = parm.CreateHttpResponse(string.Empty, filePath);

            var stream = response.GetResponseStream();

            if (stream is null)
            {
                throw new NullReferenceException(nameof(stream));
            }

            using (var reader = new StreamReader(stream, parm.EncodeType))
                return(reader.ReadToEnd());
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Downloads the file.
        /// </summary>
        /// <param name="parm"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static byte[] DownloadFile(this ResponseParam parm, FileSystemInfo filePath = null)
        {
            if (parm is null)
            {
                throw new ArgumentNullException(nameof(parm));
            }

            var response = parm.CreateHttpResponse(string.Empty, filePath);

            var st = response.GetResponseStream();

            var results = new byte[response.ContentLength];

            if (st is null)
            {
                return(results);
            }

            st.Read(results, 0, results.Length);
            st.Close();

            return(results);
        }