下面是我的代码HttpWebRequest request = null;
Stream rspStm = null;
//创建Request对象
try
{
request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.ContentType = "application/vnd.ms-excel"; //给ContentType赋值
request.CookieContainer = cc; //保存cookie
request.Method = "GET"; //提交的方法
request.Referer = "http://beidou.baidu.com/index.html#/"; //设置标头的值
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
request.KeepAlive = true;
request.Accept = "image/jpeg, image/gif, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"; HttpWebResponse response = request.GetResponse() as HttpWebResponse;
cc.Add(response.Cookies); rspStm = response.GetResponseStream(); StreamReader reader = new StreamReader(rspStm, Encoding.UTF8); string html = reader.ReadToEnd(); }
catch (Exception)
{ throw;
}
finally
{
rspStm.Close();
request.Abort();
}但是我提供的网址在Ie输入直接是一个下载页面,抓包抓取出来的数值如下:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=270CAEAD442F9B0690D86A036FA3E402; Path=/report
Content-Disposition: attachment;filename="东方海洋-账户分日报告-20120605-20120605.csv"
Content-Type: application/vnd.ms-excel
Content-Language: zh-CN
Content-Length: 239
Date: Wed, 06 Jun 2012 02:31:13 GMT
Connection: close日期,展现次数,点击次数,点击率,平均点击价格(元),千次展现成本(元),总费用(元)
2012-06-05,22240,17,0.0764%,0.97,0.74,16.42
合计:,22240,17,0.0764%,0.97,0.74,16.42这是Stream中的返回值,但是我用上面的程序,一直抓取不到他的内容,求高手指教!不胜感激!
Stream rspStm = null;
//创建Request对象
try
{
request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.ContentType = "application/vnd.ms-excel"; //给ContentType赋值
request.CookieContainer = cc; //保存cookie
request.Method = "GET"; //提交的方法
request.Referer = "http://beidou.baidu.com/index.html#/"; //设置标头的值
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
request.KeepAlive = true;
request.Accept = "image/jpeg, image/gif, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"; HttpWebResponse response = request.GetResponse() as HttpWebResponse;
cc.Add(response.Cookies); rspStm = response.GetResponseStream(); StreamReader reader = new StreamReader(rspStm, Encoding.UTF8); string html = reader.ReadToEnd(); }
catch (Exception)
{ throw;
}
finally
{
rspStm.Close();
request.Abort();
}但是我提供的网址在Ie输入直接是一个下载页面,抓包抓取出来的数值如下:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=270CAEAD442F9B0690D86A036FA3E402; Path=/report
Content-Disposition: attachment;filename="东方海洋-账户分日报告-20120605-20120605.csv"
Content-Type: application/vnd.ms-excel
Content-Language: zh-CN
Content-Length: 239
Date: Wed, 06 Jun 2012 02:31:13 GMT
Connection: close日期,展现次数,点击次数,点击率,平均点击价格(元),千次展现成本(元),总费用(元)
2012-06-05,22240,17,0.0764%,0.97,0.74,16.42
合计:,22240,17,0.0764%,0.97,0.74,16.42这是Stream中的返回值,但是我用上面的程序,一直抓取不到他的内容,求高手指教!不胜感激!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货