/// <summary> /// 模拟POST提交 /// </summary> /// <param name="postParam">参数</param> /// <returns></returns> public static string Post(Entity.ParamEntity postParam) { WebClient webClient = new WebClient(); try { if (!string.IsNullOrEmpty(postParam.Headers)) { webClient.Headers.Add(postParam.Headers); } byte[] byteInfo = webClient.UploadValues(postParam.Url, "POST", postParam.NVCollection); string stringInfo = System.Text.Encoding.UTF8.GetString(byteInfo); return(stringInfo); } catch { return(null); } }
/// <summary> /// 模拟POST提交 /// </summary> /// <typeparam name="T">实体</typeparam> /// <param name="postParam">参数</param> /// <returns></returns> public static T Post <T>(Entity.ParamEntity postParam) { try { string stringInfo = Post(postParam); if (!string.IsNullOrEmpty(stringInfo)) { return(JsonConvert.DeserializeObject <T>(stringInfo)); } else { return(default(T)); } } catch { return(default(T)); } }