我必须从网站下载文件。我完成了身份验证部分。对于文件下载,我没有指向类似文件的链接http://whatever.com/file.xlsx
我有一个这样的网址:
http://whatever.com?b_action=cognosViewer&ui.action=view&ui.object=defaultOutput(CAMID(%22eBO%3au%3a11842%22)%2ffolder%5b%40name%3d%27My%20Folders%27%5d%2freport%5b%40name%3d%27AppointmentFacility%27%5d)&ui.name=AppointmentFacility&ui.format=spreadsheetML
这是我用来下载文件的代码
public void downloadFile(string url, string fileName)
{
// Create a request using a URL that can receive a post.
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.CookieContainer = cookieContainer;
// Set the Method property of the request to GET.
request.Method = "GET";
// Get the response.
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
{
using (StreamWriter writer = new StreamWriter(fileName, false))
{
writer.Write(reader.ReadToEnd());
writer.Flush();
writer.Close();
}
}
responseStream.Close();
}
response.Close();
}
}
但下载的文件只包含:
您的报告已准备就绪,稍后将下载到您的 Web 浏览器。
如果我将链接粘贴到 chrome 中,它会显示一个网页,其中包含:您的报告....,然后开始下载。
非常感谢您的帮助!
更新:我做了 Chrome crtl+shift+i -> network
the url of the reports is : whatever.com/p2pd/servlet/dispatch/gd/CAFS3c00000054FAAAACBugIFfTwbt-vZG2RFR7xOa6-wlAebBE523zHThH-tlqz0TrwhgYlE_H4sIAAAAAAAAALMODfLxdNFQ8svyNPXNyq-wrQqt9A2JLPcNcaz0q-Kt8s*KNPGtcrRV0gQAGDKw6yoAAAA_/
如果我登录 ie 并粘贴 url,它会显示一个防火墙错误.. 正在查看会话信息以查看它,它会将它们放在它没有的链接中。
这是标题信息:
GET /p2pd/servlet/dispatch/gd/CAFS3c00000054FAAAACBugIFFtTwbt-vZG2RFR7xOa6-wlAebBE523zHThH-tlqz0TrwhgYlE_H4sIAAAAAAAAALMODfLxdNFQ8svyNPXNyq-wrQqt9A2JLPcNcaz_0q/AAAGtQAGD1w6KNPAZ0q/AAAGtKt8s6Kyo
主持人:whatever.com
连接:保持活动
用户代理:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
接受:text/html,application/xhtml+xml,application/xml;q=0.9, / ;q=0.8
推荐人:https ://whatever.com/p2pd/servlet/dispatch
接受编码:gzip、deflate、sdch
接受语言:en-US,en;q=0.8
接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie:cam_passport=101:1212028e-a300-b0b0-9a59-6b86b56842dd:2388506829;cea-ssa=假;usersessionid=AQgAAAAZQaJQGUGiUAoAAADgMgQRkOeDfHCJFAAAACBugIFFtTwbt/vZG2RFR7xOa6/wlFAAAAAhIMT47wEMbibXlyTAd0JuxNeln;CRN=listViewSeparator%3Dnone%26displayMode%3Dlist%26timeZoneID%3DCST%26format%3DHTML%26automaticPageRefresh%3D30%26columnsPerPage%3D3%26productLocale%3Den%26useAccessibilityFeatures%3Dfalse%26showWelcomePage%3Dtrue%26showOptionSummary%3Dfalse%26show%3DObjects%3Dfalse%26show%3DObjects%3Dfalse%26 26skin%3Dcorporate%26linesPerPage%3D15%26; 用户能力=7c6d%3B6f%3Bff071efa%26ARQAAAAgboCBX08G7f72RtkRUe8Tmuv8JQBBkqOE98nKAPC1mu7HFx2kwsKb;caf=CAFW000000b0Q0FGQTNjMDAwMDAwM2FGQUFBQUNCdWdJRmZUd2J0LXZaRzJSRlI3eE9hNi13bFRtOGJUc0pHalZqSW1mSWZ0VHg3emhkKnpMOF8zNzU2MTJ8MTAxOjEyMTIwMjhlLWEzMDAtYjBiMC05YTU5LTZiODZiNTY4NDJkZDoyMzg4NTA2ODI5; cc_session=s_cc:|s_conf: na|s_sch:td|s_hd:sa|s_serv:na|s_disp:na|s_set:|s_dep:na|s_dir:na|s_sms:dd|s_ct:sa|s_cs:sa|s_so:sa|e_hp:CAMID(* 22eBO*3au*3a11842*22)|e_proot:Public*20Folders|prootid:i9E956E6B64DA4217A97F144A433887C1|e_mroot:My*20Folders|mrootid:iD973C48427A94A9AAFB17F9016C8A62A|e_mrootpath:CAMID(*22eBO*3au*3a11842*22)*2ffolder*5b*40name*3d *27My*20Folders*27*5d|e_user:FirstName*20LastName|cl:en|dcid:i9E956E6B64DA4217A97F144A433887C1|show_logon:false|uig:|ui:|write:true|eom:0|pp:2388506829|cachestamp:2012-11 -06T07:46:19;ARAHHC-eBO=ARAHHC-Arka-eBO2 CAMID(*22eBO*3au*3a11842*22)*2ffolder*5b*40name*3d*27My*20Folders*27*5d|e_user:FirstName*20LastName|cl:en|dcid:i9E956E6B64DA4217A97F144A433887C1|show_logon:false|uig:|ui :|write:true|eom:0|pp:2388506829|cachestamp:2012-11-06T07:46:19; ARAHHC-eBO=ARAHHC-Arka-eBO2 CAMID(*22eBO*3au*3a11842*22)*2ffolder*5b*40name*3d*27My*20Folders*27*5d|e_user:FirstName*20LastName|cl:en|dcid:i9E956E6B64DA4217A97F144A433887C1|show_logon:false|uig:|ui :|write:true|eom:0|pp:2388506829|cachestamp:2012-11-06T07:46:19; ARAHHC-eBO=ARAHHC-Arka-eBO2