博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转】根据URL来读取网页输出的数据
阅读量:7086 次
发布时间:2019-06-28

本文共 1982 字,大约阅读时间需要 6 分钟。

读取网页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 = ;        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("");            //this.Close();        }

 

转载于:https://www.cnblogs.com/gzh4455/archive/2012/07/09/2582420.html

你可能感兴趣的文章
Initializing the Oracle ASMLib driver: [FAILED]
查看>>
innodb_force_recovery强制修复MySQL异常关闭问题
查看>>
keepalived 实用简介
查看>>
svn http运行
查看>>
如何将Windows XP SP3改成SP2
查看>>
我的友情链接
查看>>
Spring 3.0
查看>>
curl 模拟qq登录
查看>>
从概念理解Lucene的Index(索引)文档模型
查看>>
实战MYSQL 8.0.12 主主复制配置过程
查看>>
IBM ServerGuide 9.0
查看>>
网维大师有盘网吧实施方案
查看>>
sql优化(三)
查看>>
转载:在 ANDROID DIALOG中使用AUTOCOMPLETETEXT
查看>>
spring boot 拦截器、过滤器、监听器、定时器使用
查看>>
java8新特性介绍(一)
查看>>
查看Linux服务器有没有无线网卡
查看>>
2015年10月23日作业
查看>>
Python---列表生成式
查看>>
学生信息管理系统改编
查看>>