简体   繁体   中英

C# WebClient DownloadString and DownloadFile giving different results

I am attempting to retrieve some information from a website, parse out a specific item, and then move on with my life.

I noticed that when I check "view source" on the website, the results match with what I see when I use the WebClient class' method of DownloadFile. On the other hand, when I use the DownloadString method, the contents of that string are different from both view source and DownloadFile.

I need DownloadString to return similar contents to view source and DownloadFile. Any suggestions? My relevant code is below:

string criticalPathUrl = "http://blahblahblah&sessionId=" + sessionId;

WebClient wc = new WebClient();
wc.Encoding = System.Text.Encoding.UTF8;

//this is different
string urlContentsString = wc.DownloadString(criticalPathUrl);

//than this
wc.DownloadFile(criticalPathUrl, "rawDlTxt2.txt");

Edit: Please ignore this question as I just didn't scroll up far enough. Ugh. One of those days.

use download data instead of downloadstring and use suitable encoding to convert the string then save the file!

watch details: https://www.pavey.me/2016/04/aspnet-c-downloadstring-vs-downloaddata.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM