zoukankan      html  css  js  c++  java
  • 实现http访问

      //实现http访问
                try
                {
                    string getpage = @"http://192.168.0.36:8082/News/PlusNews.aspx";
                    CookieContainer cc = new CookieContainer();
                    string content = string.Empty;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(getpage);
                    request.Method = "post";
                    request.Timeout = 10000;
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = content.Length;//???? 
                    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)";
                 
                    request.CookieContainer = cc;
                    //Stream stream = request.GetRequestStream();
                    //StreamWriter writer = new StreamWriter(stream, Encoding.GetEncoding("gb2312"));
                    //writer.Write(content, 0, content.Length);
                    //writer.Close();
                    //stream.Close();
                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    response.Cookies = cc.GetCookies(request.RequestUri);
                    Stream readerStream = response.GetResponseStream();
                    StreamReader sr = new StreamReader(readerStream, Encoding.GetEncoding("gb2312"));
                    content = sr.ReadToEnd();
                    sr.Close();
                    readerStream.Close();
                    //return content;
                }
                catch (Exception e)
                {
                    Exception e1 = e;
                    //return null;
                } 
  • 相关阅读:
    eclipse文件编辑器相关概念
    Oracle ROLLUP和CUBE 用法
    eclipse插件开发常用的选择器
    oracle多cpu并行查询
    MYECLISE6.5下CDT安装
    oracle SAMPLE 语法应用
    常用的gcc命令
    vbscript获取本机的ip地址和mac地址
    什么是Single Sign On
    eclipse插件开发中全局对象的获取
  • 原文地址:https://www.cnblogs.com/jameshappy/p/2688325.html
Copyright © 2011-2022 走看看