看到的一个城市天气预报的数据,而获取的源文件代码是:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=gb2312">
  <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
  <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
  <link href="/gifs/favicon.ico" rel="shortcut icon">
  <META HTTP-EQUIV="EXPIRES" CONTENT="0">
  <TITLE>天气在线</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff"><br>&nbsp;<br>看不到预报吗?请将您的浏览器设成接受Cookies,然后刷新页面。<br><br>步骤如下:<br>点击浏览器上的工具栏, 打开Internet选项, 点击隐私, 将移动滑块向下拉到中高,然后刷新页面即可。</BODY><!-- Host: jedi-11.wetteronline.de -->
</HTML>我按照提示设置cookie在最低也没有用啊。 我的程序里面也加上了cookie包含啊,如下:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
request.Timeout = 600000;
request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
Stream resStream = response.GetResponseStream(); 

StreamReader reader = new StreamReader(resStream,System.Text.Encoding.GetEncoding("Gb2312"));
while( (line = reader.ReadLine())!=null )
{
buffer+=line+"\r\n";
}

解决方案 »

  1.   

    Uri uri = new Uri(url); 
    WebRequest wr = WebRequest.Create(uri); 
    Stream s = wr.GetResponse().GetResponseStream(); 
    StreamReader sr = new StreamReader(s, Encoding.Default); 

    str= sr.ReadToEnd(); 
    你测试以下,返回的值是否正确
      

  2.   

    你只是初始化了一个,并没有添加Cookie,参看
    http://www.blogcn.com/user40/hero3king/blog/22968580.html
      

  3.   


    你只是初始化了一个CookieContainer,并没有添加Cookie,参看
    http://www.blogcn.com/user40/hero3king/blog/22968580.html