zoukankan      html  css  js  c++  java
  • WebRequest发送请求并接收返回值

    public string getXmlStr(string hphmcode)
            {
                string Url = "http://localhost:8080/readvioinfo.jsp";
                string hphm = hphmcode;
                string hpzl = "02";
                //Encoding encoding = Encoding.GetEncoding("utf-8");
                Encoding encoding = Encoding.GetEncoding("GB2312");
                 string postData = "hphm=" + hphm + "&hpzl=" + hpzl;
                byte[] data = encoding.GetBytes(postData);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                //发送数据
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
                //接收返回值
                HttpWebResponse res = (HttpWebResponse)request.GetResponse();
                StreamReader sReader = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
                string strBack = sReader.ReadToEnd();
                //Response.Write(strBack);
                sReader.Close();
                res.Close();
                return strBack;
            }

    每天积累一点,离成功就近一点
  • 相关阅读:
    15 反转链表
    八大排序算法总结(2)
    八大排序算法总结(1)
    22从上往下打印二叉树
    19顺时针打印矩阵
    20包含min函数的栈
    SpringMVC-Mybatis整合和注解开发
    优雅的代码之选择不同支付方式
    利用freemarker+SAX解析xml的方式对excel文件字段校验
    pl/sql编程语言
  • 原文地址:https://www.cnblogs.com/apes-monkeys/p/4031213.html
Copyright © 2011-2022 走看看