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;
                } 
  • 相关阅读:
    Android控件显示和隐藏
    Android Viewpager+Fragment实现滑动标签页
    Android中的color使用
    Android自定义Button按钮显示样式
    Android通过Intent传递对象
    Android中AsyncTask的使用
    iOS,推送通知
    UIWebView与JS的交互
    iOS蓝牙中的进制转换,数据格式转换
    Core Graphics 定制UIVIew 处理图片
  • 原文地址:https://www.cnblogs.com/jameshappy/p/2688325.html