1

I`m trying to download string from address "http://www.last.fm/music/Boney%20M./+images",but return null,

WebClient webClient = new WebClient();
string html = webClient.DownloadString(new Uri("http://www.last.fm/music/Boney%20M./+images"));
vothanhdat
  • 89
  • 1
  • 7
  • When visiting with my browser, i think it redirected to `http://www.last.fm/music/Boney+M./+images` (notice the missing `%20`). I dont know how WebClient handles redirects but Try that new redirected address and see what happens. – mrmoje Aug 17 '13 at 16:15
  • @Moje I believe you're on to something. When executing the above in PowerShell I got `Exception calling "DownloadString" with "1" argument(s): "Too many automatic redirections were attempted."`. FWIW, replacing the space with a `+` doesn't seem to help either. – lc. Aug 17 '13 at 16:18
  • Possibly related: http://stackoverflow.com/questions/518181/too-many-automatic-redirections-were-attempted-error-message-when-using-a-http – lc. Aug 17 '13 at 16:23
  • Doesn't make sense here. The first redirect changes the space to a `+`. But if I retry with that address I'm getting *another* redirect to itself. I'm guessing it's looking for some headers and caught in a redirect loop since they are missing... I wonder why @OnoSendai got it to work. – lc. Aug 17 '13 at 16:34

1 Answers1

1

Just tried it on a test application under VS2012 Express, and it's working as intended.

Some thoughts:

  • The problem may lie in the fact that you are behind a proxy, and you may need to create a WebProxy object and provide your credentials.
  • Sometimes (which is not the case, since it worked for me) sites expect some headers - for example HTTP_REFERER.
OnoSendai
  • 3,960
  • 2
  • 22
  • 46