zoukankan      html  css  js  c++  java
  • WebClient 使用

    --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;
            }

  • 相关阅读:
    转 configure: error: Cannot find ldap.h
    DDoS(Distributed Denial of Service,分布式拒绝服务)
    j2ee 1.5和1.6的区别
    机器学习
    免安装版Tomcat6.0启动方法
    mysql补充(2)常用sql语句
    mysql补充(4)数据完整性
    mysql补充(3)优化sql语句查询常用的30种方法
    mysql补充(1)校对集utf8_unicode_ci与utf8_general_ci
    jdbc(1)(一)
  • 原文地址:https://www.cnblogs.com/zhtbk/p/4530756.html
Copyright © 2011-2022 走看看