using System;
using System.Net.Http;
using NewLife.Http;
using RestSharp;
namespace Tool
{
public class HttpUtil
{
///
/// 提交json字符
///
///
///
///
public static (bool b,string msg) PostJson(string url, object obj)
{
try
{
var client = new RestClient(url);
var request = new RestRequest();
request.AddHeader("Content-Type", "application/json");
request.Method = Method.Post;
request.Timeout = TimeSpan.FromMinutes(2);
request.AddBody(obj, ContentType.Json);
var response = client.Execute(request);
return (response.IsSuccessful, response.IsSuccessful ? response.Content : response.ErrorMessage);
}
catch (Exception e)
{
ILogNetFactory.GetLogNet.WriteError(e.Message);
return (false, e.Message);
}
}
}
}