.net - Using WebClient to login and download files -


i've found different examples of doing this, haven't been able combination of them work.

basically, have intranet system can generate documents web link, , know ones want download. able generate list of links want download, run problems authenticating system within program. keep getting 401 error this:

public shared sub downloadfiles(_tool tool)     dim links list(of string) = getjiralinks(_tool)      dim downloader new webclient      ' initialize client     dim reqparm new specialized.namevaluecollection      reqparm.add("os_username", "user")     reqparm.add("os_password", "pass")     reqparm.add("os_destination", "/secure/")      downloader.credentials = new networkcredential("user", "pass")      dim uploadlocation string = my.settings.jiralocation & "login.jsp"      'downloader.headers.add("content-type", "application/x-www-form-urlencoded")      dim responsebytes = downloader.uploadvalues(uploadlocation, "post", reqparm)      dim responsebody = (new text.utf8encoding).getstring(responsebytes)      dim workingdir string = createworkingdir()      each link string in links         dim tempuri new uri(link)          dim localpath string = workingdir & "\" & system.io.path.getfilename(tempuri.localpath)          downloader.downloadfile(tempuri, localpath)     next end sub 

i figured post working example of solution. many other posts link cookie aware web client (how can webclient use cookies?) fail show in action. here's mine:

public shared sub downloadfiles(_tool tool)     dim links list(of string) = getjiralinks(_tool)      dim downloader new cookieawarewebclient      ' start requesting page.      dim loginpage string = my.settings.jiralocation & "login.jsp"      ' initialize client     dim reqparm new specialized.namevaluecollection      reqparm.add("os_username", "user")     reqparm.add("os_password", "pass")     reqparm.add("os_destination", "/secure/")      dim responsebytes = downloader.uploadvalues(loginpage, "post", reqparm)      dim responsebody = (new text.utf8encoding).getstring(responsebytes)      dim workingdir string = createworkingdir()      each link string in links         dim tempuri new uri(link)          dim localpath string = workingdir & "\" & system.io.path.getfilename(tempuri.localpath)          downloader.downloadfile(tempuri, localpath)     next end sub 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -