您的位置:首页 > 运维架构 > 网站架构

C#用webclient 实现模拟登陆网站(未完成)笔记

2013-09-22 20:14 435 查看
using System.Net;
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead("http://www.baidu.com");
StreamReader reader = new StreamReader(data);
String s = reader.ReadToEnd();
Console.WriteLine(s);http://write.blog.csdn.net/postedit/11907597
Console.ReadKey();


///////下面是HttpWebRequest 的介绍

HttpWebRequest  是.net 基类库的一个类,用来使用户通过HTTP 协议和服务器交互

通常数据的体积哦啊是通过GET  和POST 两种方式来完成的

1 GET方式:

HttpWebRequest  req=(HttpWebRequest)HttpWebRequest.create("http://baidu.com/intl/zh=CN/");

req.Method="GET";

using (WebResponse wr=req.GetResPonse())

{

}

2....使用POST 方式

String param="hi=zh-CN&newwindow=1";

byte[] bs=Encoding.ASCII.GetByte(param);

HttpWebRequest  req=(HttpWebRequest)HttpWebRequest.create("http://baidu.com/intl/zh=CN/");

req, Method="POST";

req.ContentType =“application/x=www-form=urlencoded”;

req.ContentLength=bs.length;

using(Stream reqStream=req.GetRequestStream())

{

reqStream.write(bs,0,bs.length);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: