Пример #1
0
 /// <summary>
 /// 发起Post请求,可上传文件
 /// </summary>
 /// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
 /// <param name="url">请求Url</param>
 /// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
 /// <param name="encoding"></param>
 /// <param name="cer">证书,如果不需要则保留null</param>
 /// <param name="timeOut">代理请求超时时间(毫秒)</param>
 /// <param name="fileDictionary"></param>
 /// <param name="postDataDictionary"></param>
 /// <returns></returns>
 public static T PostFileGetJson <T>(string url
                                     , CookieContainer cookieContainer                = null
                                     , Dictionary <string, string> fileDictionary     = null
                                     , Dictionary <string, string> postDataDictionary = null
                                     , Encoding encoding   = null
                                     , X509Certificate cer = null
                                     , int timeOut         = Config.TIME_OUT)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         postDataDictionary.FillFormDataStream(ms); //填充formData
         string returnText = RequestUtility.HttpPost(url, cookieContainer, ms, fileDictionary, null, encoding, cer, timeOut);
         var    result     = GetResult <T>(returnText);
         return(result);
     }
 }
Пример #2
0
        /// <summary>
        /// 【异步方法】PostGetJson的异步版本
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url"></param>
        /// <param name="cookieContainer"></param>
        /// <param name="fileStream"></param>
        /// <param name="encoding"></param>
        /// <param name="cer">证书,如果不需要则保留null</param>
        /// <param name="timeOut"></param>
        /// <param name="checkValidationResult"></param>
        /// <returns></returns>
        public static async Task <T> PostGetJsonAsync <T>(string url
                                                          , CookieContainer cookieContainer = null
                                                          , Stream fileStream          = null
                                                          , Encoding encoding          = null
                                                          , X509Certificate cer        = null
                                                          , int timeOut                = Config.TIME_OUT
                                                          , bool checkValidationResult = false)
        {
            string returnText = await RequestUtility.HttpPostAsync(url, cookieContainer, fileStream, null, null, encoding, cer, timeOut, checkValidationResult);

            AliTrace.SendApiLog(url, returnText);

            var result = GetResult <T>(returnText);

            return(result);
        }