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

  • 相关阅读:
    iOS 在Host App 与 App Extension 之间发送通知
    将博客搬至CSDN
    ios7 UITableView 分割线在 使用selectedBackgroundView 选中时有些不显示
    UITableViewCell 分割线如何满屏
    CocoaPods管理的项目移植到别人电脑后找不到头文件
    iOS Touch ID 简易开发教程
    iOS内存泄露统计
    iOS开发之Objective-c的AES128加密和解密算法的实现
    iOS中使用RNCryptor对资源文件加密
    iOS持续集成:命令行创建工程
  • 原文地址:https://www.cnblogs.com/a546558309/p/2194492.html
Copyright © 2011-2022 走看看