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;
                } 
  • 相关阅读:
    香港增补字符集(HKSCS) 背景介绍
    Java是剑客飘逸;.NET是刀客霸道 (二)
    sql server中扩展存储过程
    《Windows Communication Foundation之旅》系列之三
    《WCF之旅》系列
    男性英文名字汉语意思大全
    AJAX基础教程
    《Windows Communication Foundation之旅》系列之四
    《Windows Communication Foundation之旅》系列之一
    XSL进阶教程
  • 原文地址:https://www.cnblogs.com/jameshappy/p/2688325.html
Copyright © 2011-2022 走看看