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

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -