• Http远程调用服务


    GET          

      public static string GetJsonStr(string webApi)
            {
                string serviceAddress = webApi;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
                request.Method = "GET";
                request.ContentType = "application/json;charset=UTF-8";
                //request.ContentType = "application/text";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream myResponseStream = response.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
                string retString = myStreamReader.ReadToEnd();
                return retString;
            }
                =============================

       POST

     public static string PostJsonStr(string webApi, string data)
            {
                WebRequest request = WebRequest.Create(webApi);
                request.Method = "Post";
                request.ContentType = "application/json;charset=utf-8";
                //request.ContentLength = data.Length;
                StreamWriter sw = new StreamWriter(request.GetRequestStream());
                request.Timeout = 1000*60*2;//超时时间
                sw.Write(data);
                sw.Flush();
                WebResponse response = request.GetResponse();
               
                Stream s = response.GetResponseStream();
                StreamReader sr = new StreamReader(s, Encoding.GetEncoding("utf-8"));
                string readStr = (sr.ReadToEnd());
                return readStr;
            }

  • 相关阅读:
    vxlan 内核实现
    perf 系统调用
    quic NAT
    机器学习在ABR算法中的应用纵览
    清华最新AIOps案例:强化学习,降低网络传输延时
    内核gso
    怎么提高网络应用性能?让DPDK GRO和GSO来帮你!
    网卡VXLAN的offload技术介绍
    Matplotlib中的plt和ax画图的区别
    Task 3: 异常处理(2天)
  • 原文地址:https://www.cnblogs.com/suppler/p/6169248.html
Copyright © 2020-2023  润新知