目的,把远程服务器传回的html,解析到类里面,为gridview等提供数据源
1 、向远程服务器post数据
public int postdata(string url, string data, out string info)
{
info = "";
cookiecontainer cc = new cookiecontainer();
httpwebrequest request = webrequest.create(url) as httpwebrequest;
request.cookiecontainer = cc;
request.method = "post";
request.contenttype = "application/x-www-form-urlencoded";
stream requeststream = request.getrequeststream();
byte[] bytearray = encoding.utf8.getbytes(data);
requeststream.write(bytearray, 0, bytearray.length);
requeststream.close();
httpwebresponse response = request.getresponse() as httpwebresponse;
uri responseuri = response.responseuri;
stream receivestream = response.getresponsestream();
encoding encode = system.text.encoding.getencoding("utf-8");
streamreader readstream = new streamreader(receivestream, encode);
string result = readstream.readtoend();
info = result;
return 0;
}2、解析返回的html,有省略
public classinfo[] getclass(string html)
{
arraylist ar = new arraylist();
arraylist arr = new arraylist();
string table = "";
regex regtable = new regex(@"(?<=<table.*>).*?(?=</table>)", regexoptions.singleline);
match ma = regtable.match(html);
while (ma.success)
{
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器