コード例 #1
0
ファイル: HttpAssist.cs プロジェクト: brickjia/Common
        /// <summary>
        ///     Gets all type request data.
        /// </summary>
        /// <param name="param"></param>
        /// <param name="postParamDict"></param>
        /// <returns></returns>
        public static string GetRequestResult(this ResponseParam param,
                                              IDictionary <string, string> postParamDict = null)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var postData = string.Empty;

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

            var response = param.CreateHttpResponse(postData);
            var stream   = response.GetResponseStream();

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

            using (var reader = new StreamReader(stream, param.EncodeType))
            {
                return(reader.ReadToEnd());
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets all type request string data.
        /// </summary>
        /// <param name="param"></param>
        /// <param name="url"></param>
        /// <param name="filePath"></param>
        /// <param name="postData"></param>
        /// <returns></returns>
        public static string GetTypeRequest(this ResponseParam param, string url, string filePath = null, string postData = null)
        {
            var response = param.CreateHttpResponse(url, filePath, postData);

            using (var reader = new StreamReader(response.GetResponseStream(), param.EncodeType))
                return(reader.ReadToEnd());
        }
コード例 #3
0
        /// <summary>
        /// Uploads the file.
        /// </summary>
        /// <param name="param"></param>
        /// <param name="url"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string UploadFile(this ResponseParam param, string url, string filePath)
        {
            var response = param.CreateHttpResponse(url, filePath);

            using (var reader = new StreamReader(response.GetResponseStream(), param.EncodeType))
                return(reader.ReadToEnd());
        }
コード例 #4
0
        /// <summary>
        /// Downloads the file.
        /// </summary>
        /// <param name="param"></param>
        /// <param name="url"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static byte[] DownloadFile(this ResponseParam param, string url, string filePath = null)
        {
            var response = param.CreateHttpResponse(url, filePath);
            var st       = response.GetResponseStream();
            var results  = new byte[response.ContentLength];

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

            return(results);
        }
コード例 #5
0
        /// <summary>
        /// Uploads the file.
        /// </summary>
        /// <param name="param"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string UploadFile(this ResponseParam param, FileSystemInfo filePath = null)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

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

            using (var reader = new StreamReader(response.GetResponseStream(), param.EncodeType))
                return(reader.ReadToEnd());
        }
コード例 #6
0
        /// <summary>
        /// Downloads the file.
        /// </summary>
        /// <param name="param"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static byte[] DownloadFile(this ResponseParam param, FileSystemInfo filePath = null)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var response = param.CreateHttpResponse(string.Empty, filePath);
            var st       = response.GetResponseStream();
            var results  = new byte[response.ContentLength];

            if (st != null)
            {
                st.Read(results, 0, results.Length);
                st.Close();
            }

            return(results);
        }