• 【转】根据URL来读取网页输出的数据


    读取网页Reponse数据,下面是一个浪驰短信的实例

     public static string HttpSMSPost(HttpWebRequest hr, string url, string parameters)
             {
                string strRet = null;
                ASCIIEncoding encoding = new ASCIIEncoding(); 
                byte[] data = encoding.GetBytes(parameters); 
    
                try
                {
                    hr.KeepAlive = false;
                    hr.Method = "POST";
                    hr.ContentType = "application/x-www-form-urlencoded";
                    hr.ContentLength = data.Length; 
                    Stream newStream = hr.GetRequestStream();
                    newStream.Write(data, 0, data.Length);
                    newStream.Close();
    
                    HttpWebResponse myResponse = (HttpWebResponse)hr.GetResponse();    
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
                    strRet = reader.ReadToEnd();      
                    reader.Close();
                    myResponse.Close();
    
                    return strRet;
            
                }
                catch (Exception ex)
                {
                    strRet = "-200";
                }
                return strRet;
            }


    使用:

            string url = http://test.com/Login.asp;
            string SMSparameters = "UserID=" + Userid + "&Account=" + Account + "&Password=" + PassWord;
    
            string targeturl = url.Trim().ToString();
            HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
            hr.CookieContainer = cookieContainerSMS;
            string res = httpPost.HttpSMSPost(hr, url, SMSparameters);
    
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(res);
            string errorNum = xml.SelectSingleNode("/LANZ_ROOT/ErrorNum").InnerText;  //获取是否登陆成功
    
            ActiveID = xml.SelectSingleNode("/LANZ_ROOT/ActiveID").InnerText;  //获取成功后的ActiveID 
            if (errorNum == "0")
            {
                //this.Close();
                Response.Write("登陆成功");
            }
            else
            {
                Response.Write("<script>alert('登陆失败')</script>");
                //this.Close();
            }
  • 相关阅读:
    获取用户登录次数(cookie)
    漂亮的 Checkbox and Radio (jQuery)
    FancyUpload3.0
    UI upload 多文件上传
    js 匿名函数 闭包
    c# 图片插入Excel
    sql查询优化 索引优化
    GridViewAddUpdateDelete_Ajax with jquery.blockUI
    动态自动搜索 Dynamic search (js版)
    master.dbo.spt_values
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2582420.html
Copyright © 2020-2023  润新知