How do I download with c# ?

D

Du Dang

i wanna create a bot to download wallpaper from a website
cuz there are thousands of pic availiable and right click and "save as"
ain't fun no more

so far i got this from google

+++++++++++

WebClient Client = new WebClient();
Client.DownloadFile(url, save_as);

+++++++++++

but that code can only download static url only
ie. http://www.google.ca/intl/en_ca/images/logo.gif

but it doesn't work for links like
http://www.themexp.org/download.php?type=wp&id=96
it keep giving me http 400 error (bad request)

any help is appreciated

thanks

Du
 
G

Greg Ewing [MVP]

Du, have you tried to set the QueryString property of the WebClient object?
So, your code would look like this:
string url = "http://www.themexp.org/download.php";
string qs = "?type=wp&id=96";
WebClient Client = new WebClient();
Client.QueryString = qs;
Client.DownloadFile(url, save_as);
 
C

Chris Capel

Du,

The second URL returns a page with a redirect of some sort (http header or
javascript) that causes Internet Explorer to download the file. It's not a
direct link to the file. The reason it's like this is that the creators of
the website wanted to prevent people like you from automated downloading
like you're trying to do. If you decide not to respect their wishes, then
there's certainly a way to get the file anyway. It's possible that the
server is rejecting the request from your code to download the second link
because of the information sent in the HTTP header. Specifically, the
themexp server could be checking which client you're using to make sure it's
a browser. You'll have to spoof the header of the request sent using
WebClient somehow. I don't know if that's easily possible or not. You may
have to use a different library to send the web request, or do it yourself
using sockets. But it's a direction for you.

Chris
 
D

Du Dang

Thanks to Greg and Chris for helping me out...

I haven't get it to work yet .. but now i have a lead to follow

thanks again !!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top