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.
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using NewLife.Http;
|
|
|
|
|
using RestSharp;
|
|
|
|
|
|
|
|
|
|
namespace Tool
|
|
|
|
|
{
|
|
|
|
|
public class HttpUtil
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交json字符
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|