C# 获取时间戳

2021-03-17 14:25

阅读:644

标签:地址   color   eth   ring   headers   pen   lang   gen   byte   

1

long timestamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;

2

        /// 
        /// 指定Post地址使用Get 方式获取全部字符串
        /// 
        /// 请求后台地址
        /// 
        public static string Post(string url, Dictionarystring, string> dic)
        {
            string result = "";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            //req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            //req.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
            //req.UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:12.0) Gecko/20100101 Firefox/12.0";
            #region 添加Post 参数
            StringBuilder builder = new StringBuilder();
            int i = 0;
            foreach (var item in dic)
            {
                if (i > 0)
                    builder.Append("&");
                builder.AppendFormat("{0}={1}", item.Key, item.Value);
                i++;
            }
            byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
            req.ContentLength = data.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            #endregion
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            Stream stream = resp.GetResponseStream();
            //获取响应内容
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
            return result;
        }

 

C# 获取时间戳

标签:地址   color   eth   ring   headers   pen   lang   gen   byte   

原文地址:https://www.cnblogs.com/kikyoqiang/p/12386180.html


评论


亲,登录后才可以留言!