using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Zxd.Crm.Domain.Config
{
public static class Utility
{
///
/// 获取数据
///
///
///
///
public static string GetData(string Url, string RequestPara, IDictionary headers, Encoding encoding, int timeout = 5000)
{
RequestPara = RequestPara.IndexOf('?') > -1 ? (RequestPara) : ("?" + RequestPara);
WebRequest hr = HttpWebRequest.Create(Url + RequestPara);
byte[] buf = encoding.GetBytes(RequestPara);
hr.Method = "GET";
hr.Timeout = timeout;
foreach (var item in headers)
{
hr.Headers.Add(item.Key, item.Value);
}
System.Net.WebResponse response = hr.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
string ReturnVal = reader.ReadToEnd();
reader.Close();
response.Close();
return ReturnVal;
}
///
/// 时间戳转为C#格式时间
///
///
///
public static DateTime ConvertStringToDateTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
}
}