C# download image from src without extension -
i download image url http://squirlytraffic.com/surficon.php?ts=1491591235
i tried code don't see image when open it.
using (webclient client = new webclient()) { client.downloadfile("http://squirlytraffic.com/surficon.php?ts=1491591235", @"d:\image.jpg"); }
you need set credentials using the webclient credentials property. can assigning instance of networkcredential. see below:
using (webclient client = new webclient()){ client.credentials = new networkcredential("user-name", "password"); client.downloadfile("url", @"file-location"); } edit
if don't want hard code username , password, can set usedefaultcredentials property of webclient true. use credentials of logged in user. documentation.
the credentials property contains authentication credentials used access resource on host. in client-side scenarios, should use defaultcredentials, credentials of logged on user. this, set usedefaultcredentials property true instead of setting property.
which mean amend above code to:
using (webclient client = new webclient()){ client.usedefaultcredentials = true; client.downloadfile("url", @"file-location"); }
Comments
Post a Comment