Exemple #1
0
        /// <summary>
        ///  POST请求
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="session">参数</param>
        /// <returns></returns>
        public string HttpPost(string url, string param, UserInfoUnDeteil userinfo)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = "POST";
            request.ContentType = "text/json; charset=UTF-8";
            var    model = new Parameter(param, userinfo);
            string json  = JsonConvert.SerializeObject(model);

            using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
            {
                dataStream.Write(json);
                dataStream.Close();
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string          encoding = response.ContentEncoding;

            if (encoding == null || encoding.Length < 1)
            {
                encoding = "UTF-8"; //默认编码
            }
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));

            return(reader.ReadToEnd());
        }
Exemple #2
0
        public Parameter(string info, UserInfoUnDeteil userinfo)
        {
            this.info = info;
            if (userinfo != null && userinfo.UserInfo.Lng == null && userinfo.UserInfo.Lat == null)
            {
                var ClientIpAddress = JsonConvert.DeserializeObject <Root>(BaidOrdinaryRequest.BaidApiGetRequestIpAddress(userinfo.UserInfo.Ip));
                if (ClientIpAddress.error == 0 && ClientIpAddress.data != null)
                {
                    userinfo.UserInfo.Lat = ClientIpAddress.data.Lat;
                    userinfo.UserInfo.Lng = ClientIpAddress.data.Lng;
                    if (!userinfo.UserInfo.Isp.Contains(ClientIpAddress.data.Province) || !userinfo.UserInfo.Isp.Contains(ClientIpAddress.data.City))
                    {
                        userinfo.UserInfo.Isp = userinfo.UserInfo.Isp + "[" + ClientIpAddress.data.Province + ClientIpAddress.data.City + ClientIpAddress.data.Country + "]";
                    }
                    //UserInfoBLL userinfobll = new UserInfoBLL();
                    //userinfobll.Update(userinfo.UserInfo);
                    CacheHelper.RemoveAllCache(userinfo.Key);
                    CacheHelper.SetCache(userinfo.Key, userinfo);
                }
                else
                {
                    return;
                }
            }
            int result;

            int.TryParse(userinfo.UserInfo.Ip.Replace(".", ""), out result);
            if (result != 0)
            {
                userid = result;
            }
            else
            {
                userid = 123;
            }
            double reslut_lng;

            Double.TryParse(userinfo.UserInfo.Lng, out reslut_lng);
            if (reslut_lng > 1)
            {
                this.lon = Convert.ToDouble(reslut_lng).ToString("0.000000");
            }
            double reslut_lat;

            Double.TryParse(userinfo.UserInfo.Lat, out reslut_lat);
            if (reslut_lat > 1)
            {
                this.lat = Convert.ToDouble(reslut_lat).ToString("0.000000");
            }
            if (userinfo.UserInfo.Isp.Contains(" "))
            {
                this.loc = userinfo.UserInfo.Isp.Split(' ')[0];
            }
            else
            {
                this.loc = userinfo.UserInfo.Isp;
            }
        }