首页 > Web开发 > 详细

WebClient 使用

时间:2015-05-26 17:48:09      阅读:187      评论:0      收藏:0      [点我收藏+]

--post  请求

public static string PostMsg(Guid orgid, int page, int rows)
        {
            System.Net.WebClient client = new System.Net.WebClient();

            string postData = "{\"groupid\": \"c3c5e53cd423480aa907f123338e0850\",\"type\": [\"1\",\"3\",\"4\"],\"start\":\"" + page + "\",\"end\":\"" + rows + "\"}";
            byte[] sendData = Encoding.GetEncoding("GB2312").GetBytes(postData);

            client.Headers.Add("Content-Type", "application/json;charset=UTF-8");
            client.Headers.Add("ContentLength", sendData.Length.ToString());

            var recData = client.UploadData("http://122.226.255.148:8098/aam/rest/member/query", "POST", sendData);

            var result = Encoding.GetEncoding("UTF-8").GetString(recData);
            return result;
        }



--get  请求


  /// <summary>
        /// 发送http请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static string PostMsg(string url)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            System.IO.Stream strm = client.OpenRead(url);
            System.IO.StreamReader reader = new System.IO.StreamReader(strm);
            string resultData = reader.ReadToEnd();
            return resultData;
        }

WebClient 使用

原文:http://www.cnblogs.com/zhtbk/p/4530756.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!