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;
                } 
  • 相关阅读:
    【Kubernetes学习笔记】-kubeadm 手动搭建kubernetes 集群
    教你快速搭建NFS服务
    【Kubernetes学习笔记】-服务访问之 IP & Port & Endpoint 辨析
    【Kubernetes学习笔记】-使用Minikube快速部署K8S单机学习环境
    Linux RDP 会话中无法打开VSCode 解决办法
    Jenkins 凭证管理
    linux 后台运行进程:& , nohup
    使用私有gitlab搭建gitbook持续集成
    VS Code 使用
    Markdown Rules 详解
  • 原文地址:https://www.cnblogs.com/jameshappy/p/2688325.html
Copyright © 2011-2022 走看看