53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 获取数据
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <param name="encoding"></param>
|
|
/// <returns></returns>
|
|
public static string GetData(string Url, string RequestPara, IDictionary<string, string> 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;
|
|
}
|
|
/// <summary>
|
|
/// 时间戳转为C#格式时间
|
|
/// </summary>
|
|
/// <param name=”timeStamp”></param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
}
|
|
}
|