WebClient wc=new WebClient();
byte[] be=wc.DownloadData("http://128.adsina.allyes.com/main/adfshow?user=AFP6_for_SINA|home|homebanner01new&db=sina&border=0&local=yes");
Encoding ec=System.Text.Encoding.GetEncoding("gb2312");
string news=ec.GetString(be);正常情况下news字符串应该是wc.DownloadData("url")中URL的源代码,但是上面
的例子取到的不对(跟直接在地址栏里打开网站查看到的源代码不一样),
并且所有的这类型广告地址下载下来的都是一样的源代码。
请教如何处理才能下载下正确的源代码。谢谢
byte[] be=wc.DownloadData("http://128.adsina.allyes.com/main/adfshow?user=AFP6_for_SINA|home|homebanner01new&db=sina&border=0&local=yes");
Encoding ec=System.Text.Encoding.GetEncoding("gb2312");
string news=ec.GetString(be);正常情况下news字符串应该是wc.DownloadData("url")中URL的源代码,但是上面
的例子取到的不对(跟直接在地址栏里打开网站查看到的源代码不一样),
并且所有的这类型广告地址下载下来的都是一样的源代码。
请教如何处理才能下载下正确的源代码。谢谢
解决方案 »
- 高分,帮忙分析一下错误,System.Web.HttpUnhandledException”的异常
- .cs文件中想获取请求得到的json文件
- 请问page.LoadViewState方法调用后全部控件的视图状态都恢复了吗?
- gridview显示问题
- 文字编辑菜单和预览功能怎么实现?
- sql面试题,两小时内有效
- |M| asp.net 默认按钮 的烦心事 大家来支支招
- 请问Label控件,如何绑定ToolTip?
- LinkButton行ImageButton报错.
- 无法运行asp.net web应用程序或服务?急救!
- 各位大侠,帮帮小弟!《关于request变量》
- 把获取的数据集存在ViewState中,然后进行分页,可取不?
1 。encoding ,2 ,http头信息
public static string GetHtml(string url)
{
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.Accept=@"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
myHttpWebRequest.UserAgent=@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607; .NET CLR 1.1.4322)";
try
{
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
Stream streamResponse=myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse,Encoding.Default);
string htmlcode=streamRead.ReadToEnd();
streamRead.Close();
streamResponse.Close();
myHttpWebResponse.Close();
return htmlcode; } catch(Exception e)
{
return "error";
}
}
};保证好用
那个头信息必须在
HttpWebResponse之前加的 ,
绝不能再之后。。
试过了,直接把你的代码拷过去也是不行。
都没搞定,才疏学浅哪 ,
大哥解决时发个贴 ,
写上方法head属性一个一个的设 ,不行哪 只获得
一个空的1*1 图片服料。。