dc/Utilities/HttpUtils.cs

76 lines
2.3 KiB
C#
Raw Normal View History

2022-04-01 17:03:54 +08:00
#region << >>
/*----------------------------------------------------------------
* 13118
* 2022/3/17 14:52:03
* V1.0.0
*
*
* ----------------------------------------------------------------
*
*
*
*
* V1.0.1
*----------------------------------------------------------------*/
#endregion << >>
using ARI.EAP.HOST.SRD;
using Glorysoft.SECS.EQP.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ARI.EAP.HOST.Utilities
{
/// <summary>
/// HttpUtils 的摘要说明
/// 调用http接口工具类
/// </summary>
public static class HttpUtils
{
public static HttpWebResponse sentPOST(string url,string content)
{
HttpWebRequest postRequest=(HttpWebRequest)WebRequest.Create(url);
postRequest.Method = "POST";
postRequest.ContentType = Configuration.conf.httpConfiguration.contentType;
postRequest.Timeout = 10000;
try
{
using (StreamWriter dataStream = new StreamWriter(postRequest.GetRequestStream()))
{
dataStream.Write(content);
dataStream.Close();
}
HttpWebResponse response = (HttpWebResponse)postRequest.GetResponse();
return response;
}catch(Exception e)
{
LoggerService.SYSLogger.Error(e);
return null;
}
}
public static HttpWebResponse sentGET(string url,string param)
{
url = url + param;
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(url);
getRequest.Method = "GET";
getRequest.ContentType = Configuration.conf.httpConfiguration.contentType;
try
{
HttpWebResponse response = (HttpWebResponse)getRequest.GetResponse();
return response;
}
catch (Exception e)
{
LoggerService.SYSLogger.Error(e);
return null;
}
}
}
}