zoukankan      html  css  js  c++  java
  • 读取网络文件并获取字符窜(如获取网络Xml文件)

    public string RunRegisterNoParam(string strRegisterUrl, string param)
        {
            string strRen = "";
            try
            {
                CookieContainer container = new CookieContainer();
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strRegisterUrl + "?" + param);
                request.CookieContainer = container;
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                Stream myRequestStream = request.GetRequestStream();
                StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("utf-8"));
                myStreamWriter.Write(param);
                //把数据写入HttpWebRequest的Request流
                myStreamWriter.Close();
                myRequestStream.Close();
                //关闭打开对象
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)request.GetResponse();
                //新建一个HttpWebResponse
                myHttpWebResponse.Cookies = container.GetCookies(request.RequestUri);
                //获取一个包含url的Cookie集合的CookieCollection
                Stream myResponseStream = myHttpWebResponse.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                strRen = myStreamReader.ReadToEnd();
                //把数据从HttpWebResponse的Response流中读出
                myStreamReader.Close();
                myResponseStream.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return strRen;
        }

  • 相关阅读:
    Python()- 面向对象的组合用法
    HASHMAP 深入解析
    java深入解析
    centos 防火墙关闭/开启
    idea讲web项目部署到tomcat,热部署
    idea真不习惯啊
    JetbrainsCrack
    js 模块化
    JavaWeb中session创建与销毁的问题
    前端导出文件功能document.execCommand命令
  • 原文地址:https://www.cnblogs.com/a546558309/p/2194492.html
Copyright © 2011-2022 走看看