1

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.

Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
  • 1
    Perhaps the server isn't using UTF-8? It's very hard to know what else to say without anything more concrete to go on... you haven't even told us what *kind* of difference you're seeing. – Jon Skeet Mar 17 '17 at 22:55
  • Use the F12 tools in your browser to see what headers are being passed in the response. They can have an effect on how content is handled. – JamieSee Mar 17 '17 at 22:57
  • Thank you to both of you. Apparently, my real problem was not scrolling up far enough in the console. Everything matches. There was no problem. I am terribly sorry for inflicting my "case of the Monday on Friday" on all of you. Cheers. – Captain Ryan Mar 17 '17 at 23:15

1 Answers1

0

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

  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers/8259#8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](https://stackoverflow.com/help/deleted-answers) – Dwhitz Apr 12 '19 at 07:27