Beispiel #1
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="url">请求URL</param>
        /// <param name="requestParams">请求参数</param>
        /// <param name="filePath">文件路径</param>
        /// <param name="overWrite">是否覆盖</param>
        /// <param name="progressChanged">进度通知</param>
        /// <returns></returns>
        public AfterEvent <int> PostDownloadAsync <T>(string url, object requestParams, string filePath, bool overWrite = false, ProgressChangedEventHandler progressChanged = null)
        {
            AfterEvent <int> after = null;
            Task             t     = new Task(() =>
            {
                PostDownload(url, requestParams, filePath, overWrite, progressChanged);
                after.DoAfter(1);
            });

            t.Start();
            return(after);
        }
Beispiel #2
0
        /// <summary>
        /// 执行UploadFile请求
        /// 可接受IDictionary&lt;string,object&gt;,IEnumerable&lt;keyvaluePair&lt;string,object&gt;&gt;,
        /// IEnumerable&lt;object&gt;,string(a=a1&amp;b=b1),object等类型参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">请求url</param>
        /// <param name="requestParams">请求参数</param>
        /// <param name="fileList">文件路径列表</param>
        /// <returns></returns>
        public AfterEvent <T> UploadFileAsync <T>(string url, object requestParams = null, List <string> fileList = null)
        {
            AfterEvent <T> after = null;
            Task           t     = new Task(() =>
            {
                string resultString = UploadFile(url, requestParams, fileList);
                if (typeof(T) == typeof(string))
                {
                    T result = (T)Convert.ChangeType(resultString, typeof(T));
                    after.DoAfter(result);
                }
                else
                {
                    after.DoAfter(JsonHelper.DeserializeObject <T>(resultString));
                }
            });

            t.Start();
            return(after);
        }
Beispiel #3
0
        /// <summary>
        /// 执行Post请求
        /// 可接受IDictionary&lt;string,object&gt;,IEnumerable&lt;keyvaluePair&lt;string,object&gt;&gt;,
        /// IEnumerable&lt;object&gt;,string(a=a1&amp;b=b1),object等类型参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">请求url</param>
        /// <param name="requestParams">请求参数</param>
        /// <param name="contentType">请求内容类型</param>
        /// <returns></returns>
        public AfterEvent <T> PostAsync <T>(string url, object requestParams = null, HttpContentType contentType = HttpContentType.Json)
        {
            AfterEvent <T> after = null;
            Task           t     = new Task(() =>
            {
                string resultString = Post(url, requestParams, contentType);
                if (typeof(T) == typeof(string))
                {
                    T result = (T)Convert.ChangeType(resultString, typeof(T));
                    after.DoAfter(result);
                }
                else
                {
                    after.DoAfter(JsonHelper.DeserializeObject <T>(resultString));
                }
            });

            t.Start();
            return(after);
        }
Beispiel #4
0
        /// <summary>
        /// 执行Get请求
        /// 可接受IDictionary&lt;string,object&gt;,IEnumerable&lt;keyvaluePair&lt;string,object&gt;&gt;,
        /// IEnumerable&lt;object&gt;,string(a=a1&amp;b=b1),object等类型参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">请求URL</param>
        /// <param name="requestParams">请求参数</param>
        /// <returns></returns>
        public AfterEvent <T> GetAsync <T>(string url, object requestParams = null, IDictionary <string, string> headerParams = null, int?timeout = 60000, string userAgent = null, CookieCollection cookies = null)
        {
            AfterEvent <T> after = null;
            Task           t     = new Task(() =>
            {
                string resultString = Get(url, requestParams);
                if (typeof(T) == typeof(string))
                {
                    T result = (T)Convert.ChangeType(resultString, typeof(T));
                    after.DoAfter(result);
                }
                else
                {
                    after.DoAfter(JsonHelper.DeserializeObject <T>(resultString));
                }
            });

            t.Start();
            return(after);
        }