调用post共通方法
/// <summary>
/// les调用post接口
/// </summary>
/// <param name="resource">相对地址</param>
/// <param name="param">参数类</param>
/// <returns>IRestResponse封装好的数据</returns>
public static IRestResponse RequestPost_LesApi(string resource, object param)
{
// 配置文件中配置(system.config或者web.config)
// eg: <add key="Server.Url150" value="http://10.193.10.150:12022/" />
string path = ConfigurationManager.AppSettings["Server.Url150"];
var client = new RestClient(path);
var request = new RestRequest(Method.POST);
request.Resource = resource;
request.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["Server.Timeout"]);
if (param != null)
{
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", JsonConvert.SerializeObject(param), ParameterType.RequestBody);
}
var response = client.Execute(request);
return response;
}
调用
调用get方法
/// <summary>
/// les调用get接口
/// </summary>
/// <param name="resource">相对地址</param>
/// <param name="param">参数类</param>
/// <returns>IRestResponse封装好的数据</returns>
public static IRestResponse RequestGet(string resource, object param)
{
// 配置文件中配置(system.config或者web.config)
// eg: <add key="Server.Url150" value="http://10.193.10.150:12022/" />
string path = ConfigurationManager.AppSettings["Server.Url150"];
var client = new RestClient(path);
var request = new RestRequest(Method.GET);
request.Resource = resource;
//request.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["Server.Timeout"]);
if (param != null)
{
request.AddObject(param);
}
var response = client.Execute(request);
return response;
}
调用是一样的。