1、get或者POST传输一个小于255字节方式

传递小型数据量的信息到服务端去获取服务器信息的方法

 /// <summary>
        /// 服务端源获取信息
        /// </summary>
        /// <param name="strUrl">服务URL</param>
        /// <param name="objParemeters">参数列表(实体型)</param>
        /// <param name="ticike">身份号</param>
        /// <returns>返回结果实体</returns>
        public static T JsonRequestToObject<T>(string strUrl, Object objParemeters, string ticike)
        {
            try
            {
                Postinfo postinfo = new Postinfo();
                postinfo.ticike = ticike;
                postinfo.content = JsonConvert.SerializeObject(objParemeters);
                postinfo.Client = "PcClient";
                string param = JsonConvert.SerializeObject(postinfo);

                using (var client = new HttpClient())
                {
                    var content = new FormUrlEncodedContent(new Dictionary<string, string>()       
                    {
                       {"", param}//键名必须为空
                    });
                    var result = client.PostAsync(strUrl, content).Result.Content.ReadAsStringAsync().Result;
                    T ds = JsonConvert.DeserializeObject<T>(result);
                    return ds;
                }

            }
            catch (Exception ex)
            {
                //Log.Writer(ex.Message + ":" + ex.StackTrace);
                LogHelper.WriteLog(typeof(T), ex.StackTrace);
                object obj = Activator.CreateInstance(typeof(T));
                return (T)obj;
            }
        }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-01-22
  • 2022-12-23
  • 2021-12-31
  • 2021-06-02
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2021-08-01
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案