You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/Tool/HttpUtil.cs

40 lines
1.1 KiB
C#

2 months ago
using System;
2 months ago
using System.Net.Http;
using NewLife.Http;
2 months ago
using RestSharp;
namespace Tool
{
public class HttpUtil
{
2 months ago
2 months ago
/// <summary>
/// 提交json字符
/// </summary>
/// <param name="url"></param>
/// <param name="obj"></param>
/// <returns></returns>
2 months ago
public static (bool b,string msg) PostJson(string url, object obj)
2 months ago
{
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);
2 months ago
2 months ago
var response = client.Execute(request);
2 months ago
return (response.IsSuccessful, response.IsSuccessful ? response.Content : response.ErrorMessage);
2 months ago
}
catch (Exception e)
{
ILogNetFactory.GetLogNet.WriteError(e.Message);
2 months ago
return (false, e.Message);
2 months ago
}
}
}
}