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

    每天积累一点,离成功就近一点
  • 相关阅读:
    在cmd中登录ftp服务器
    Is valid identifier?
    Hosting Your Own NuGet Feeds
    NuGet学习笔记
    软件版本的处理
    有些事明显对自己有益,为什么却无法去做?
    .net 程序员成长路线图?
    正确跑步姿势是怎样的?
    什么叫做内心强大?怎样变成一个内心强大的人?
    使用命令行复制目录
  • 原文地址:https://www.cnblogs.com/apes-monkeys/p/4031213.html
Copyright © 2020-2023  润新知