造轮子之--ASP.Net

通过application/json方式请求数据

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "application/json";
            request.Method = "POST";

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(dataString);//Json字符串
            }

            var response = (HttpWebResponse)request.GetResponse();
            using (var streamReader = new StreamReader(response.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                return result;
            }
posted @ 2017-09-16 12:36  jl小鱼2012  阅读(123)  评论(0编辑  收藏  举报