C#WinForm如何获取网站返回的数据

liao5930 2009-04-01 05:57:59
如题,通过代码打开一个网站,并获取该网站输出的字符串,请问如何做?谢谢
...全文
813 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
deyter 2009-04-23
  • 打赏
  • 举报
回复
mark下
Radar2006 2009-04-07
  • 打赏
  • 举报
回复
private string GetWebContent(string Url)
{
string strResult="";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
    //声明一个HttpWebRequest请求
request.Timeout = 30000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
StreamReader streamReader = new StreamReader(streamReceive, Encoding.GetEncoding("GB2312"));
strResult = streamReader.ReadToEnd();
}
catch
{
MessageBox.Show("出错");
}
return strResult;
}
编程有钱人了 2009-04-07
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 liao5930 的回复:]
[Quote=引用 5 楼 wangjun8868 的回复:]
如果你这个网站的数据是动态的,那你这样就没法得到了,有没有什么办法得到呢?
[/Quote]
用线程
peterb 2009-04-06
  • 打赏
  • 举报
回复
System.Net下面的类
qisword 2009-04-06
  • 打赏
  • 举报
回复
帮你顶一下。
wanglongzhi 2009-04-06
  • 打赏
  • 举报
回复
如果你是想在程序这边传一个参数给那隐藏的网页,然后这个网页将符合这个参数的数据返回给程序的话,就试试模拟提交表单的数据的方法吧
http://www.blogjava.net/wangxinsh55/archive/2007/06/22/125847.html 可以到这里看看....
mykelly6 2009-04-06
  • 打赏
  • 举报
回复
有些可以把网页的内容获取下来自己分析,还可以传一些参数。
但是绝大多数网站是不允许这样的。
liao5930 2009-04-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wangjun8868 的回复:]
如果你这个网站的数据是动态的,那你这样就没法得到了,有没有什么办法得到呢?
jietuan 2009-04-02
  • 打赏
  • 举报
回复
你引用System.web 类,使用Httpwebrequest 获取站点页面信息
liao5930 2009-04-02
  • 打赏
  • 举报
回复
谢谢大家
ssdutght 2009-04-01
  • 打赏
  • 举报
回复
up
编程有钱人了 2009-04-01
  • 打赏
  • 举报
回复

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.bjfcdt.gov.cn/LtrAPI/happy8/v1/getAwardNumber.aspx");
request.Timeout = 20000;
request.ServicePoint.ConnectionLimit = 100;
request.ReadWriteTimeout = 30000;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if(response.StatusCode != HttpStatusCode.OK)
return;
StreamReader sr = new StreamReader(response.GetResponseStream());
while (!sr.EndOfStream)
{
string s1 = sr.ReadLine();
int index = s1.IndexOf("flow_font");
if (index != -1)
{
Console.Write(s1.Trim().Replace("</span></td>","").Substring(ss.Length)+" ");
sr.ReadLine();
for (int i = 0; i < 20; i++)
{
string s2 = sr.ReadLine();
Console.Write(s2.Trim().Substring(sss.Length, 2)+" ");
}
Console.WriteLine();
}

}
}
liao5930 2009-04-01
  • 打赏
  • 举报
回复
我见别人能从网站上得到NBA之类的信息,不知怎么做的?
FlyBee 2009-04-01
  • 打赏
  • 举报
回复
通过程序打开网站简单
 System.Diagnostics.Process.Start(url);

取该网站输出的字符串,并且能隐藏这个网站。
我也想知道。
不过lz想干什么。。。。
genius_tong 2009-04-01
  • 打赏
  • 举报
回复
UP~
liao5930 2009-04-01
  • 打赏
  • 举报
回复
并且能隐藏这个网站

110,557

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧