C# 后端post请求帮助类

/// <summary>
        /// post请求类
        /// </summary>
        /// <param name="Url">请求地址</param>
        /// <param name="Token">Token为空表示没有</param>
        /// <param name="Parameter">参数</param>
        /// <returns></returns>
        public string sendHttpPost(string Url, string Token, object Parameter)
        {
            var result = "";
            try
            {
                var client = new RestClient(Url);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("Content-Type", "application/json");
                if (!string.IsNullOrEmpty(Token))
                {
                    request.AddHeader("token", Token);
                }

                request.AddParameter("application/json", JsonConvert.SerializeObject(Parameter), ParameterType.RequestBody);
                result = client.Execute(request).Content;

            }
            catch (Exception e)
            {
                LogHelper.Error("POST数据出错", e);

            }
            return result;
        }

 

上一篇:域渗透PTT票据传递攻击(Pass the Ticket)


下一篇:SpringBoot+springCloud+eureka整合(父子聚合工程)