HttpClient post提交数据,返回json

// string data = "{\"uid\":515,\"timestamp\":\"2018 - 5 - 25 19:05:00\",\"encode\":\"3A19E9D6EAFF2FA9160ED6981EB522E1\"}";
        /// <summary>
        /// 与适当性认证相关的客户信息   XXXXXXXXXXXXXXX
        /// </summary>
        /// <param name="pid"> aid(管理人的id)</param>
        public async static void GetSpeUser(string aid)
        {
            if (string.IsNullOrEmpty(aid))
                return;
            string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var encode = string.Format("aid:{0},timestamp:{1},Appid:{2},Appkey:{3}", aid, date, Configs.SimpleBeautifulAppid, Configs.SimpleBeautifulAppkey).ToUpper();
            encode = GeneralHelper.CreateMD5(encode);
            Models.ManUserModel model = new Models.ManUserModel();
            model.aid = aid;
            model.timestamp = date;
            model.encode = encode;
            var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip };
            using (var client = new HttpClient(handler))
            {
                AppUser appuser = new AppUser();
                var content = new StringContent(JsonConvert.SerializeObject(model));
                content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
                var url = string.Format("{0}/{1}", "http://qsl.hffss.com/xem", "getSpeUser");
                client.Timeout = TimeSpan.FromSeconds(100);
                var response = await client.PostAsync(url, content);
                //确保HTTP成功状态值
                response.EnsureSuccessStatusCode();
                //await异步读取最后的JSON(注意此时gzip已经被自动解压缩了,因为上面的AutomaticDecompression = DecompressionMethods.GZip)
                var  responseString = await response.Content.ReadAsStringAsync();
                //Console.WriteLine(await response.Content.ReadAsStringAsync());
                //var response = await client.PostAsync(url, content);
                //Stream stream = await response.Content.ReadAsStreamAsync();
                //StreamReader readStream = new StreamReader(stream, Encoding.UTF8);
                //string SourceCode = readStream.ReadToEnd();
                //var response = await client.PostAsync(url, content);
                //var responseString = await response.Content.ReadAsStringAsync();
                //var list = JsonConvert.DeserializeObject<AppUser>(responseString);
            }
        }
     
上一篇:jsp和servlet+新闻发布系统


下一篇:Flash and Scalform CLIK