Esempio n. 1
0
        public static IPLocationModel GetLocation()
        {
            IPLocationWebModel model = null;

            try
            {
                CookieCollection cookie = new CookieCollection();
                string           rss1   = HttpToolPlus.Get(URL, ref cookie); //第一次请求以获取Cookie
                string           rss2   = HttpToolPlus.Get(URL, ref cookie); //携带第一次的Cookie获取数据
                model = Json.String2Object <IPLocationWebModel>(rss2);
                return(model.ToIPLocationModel());
            }
            catch (Exception e) { return(null); }
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            UserModel user = new UserModel()
            {
                Account = "123",
                Mac     = "999",
                Data    = "ajfgdkvjdhgrewiuyhnb数据"
            };

            string s = JsonTool.ToStr(user);
            Dictionary <string, string> data = new Dictionary <string, string>()
            {
                { "account", "account" }, { "mac", "mac123" }, { "data", "somedata" },
            };
            CookieCollection cookie = new CookieCollection();
            string           html   = HttpToolPlus.Post("http://localhost:9091/xtest/post1", ref cookie, data, Encoding.UTF8);


            var http   = new HttpClient();
            var httpRs = http.Post("http://localhost:9091/xtest/post3", user, HttpContentTypes.ApplicationJson);
        }
Esempio n. 3
0
        /// <summary>
        /// 短网址生成接口
        /// </summary>
        /// <param name="token">由数字和字母组成的32位字符</param>
        /// <param name="url">长网址</param>
        /// <returns></returns>
        public static DwzResponseModel Create(string token, string url)
        {
            try
            {
                string                      address = $"https://dwz.cn/admin/v2/create";
                CookieCollection            cookie  = new CookieCollection();
                DwzRequestModel             data    = new DwzRequestModel();
                Dictionary <string, string> header  = new Dictionary <string, string>();
                data.url = url;
                header.Add("Token", token);

                string           rs  = HttpToolPlus.PostJson(address, ref cookie, data, Encoding.UTF8, header);
                DwzResponseModel obj = Json.String2Object <DwzResponseModel>(rs);
                if (obj != null)
                {
                    return(obj);
                }
            }
            catch { }
            return(null);
        }