web services - How to automate downloading a files using java program -
i need download files multiple links page (may more 100 files separate links) automatically. know url login , have credentials.
i'm willing in java program automation. way go downloading location page through login site.
is curl command helpful this?
please advise me this.
you can use wget can download log files:
wget -r --no-parent --user=user --password=password --no-check-certificate <url>
- you can pass headers in --header, e.g. --header "cookie: jsonsessionid=3433434343434"
- you can pass post data using --post-data 'email=$email&password=$passwrd'
or can use following httpclient in java:
- here examples of httpclient login , passing post/get/headers information
- first whole html page string
- either parse string links files or convert java objects using xml object mappers https://github.com/fasterxml/jackson-dataformat-xml
- once links of files download files using httpclient
public void savefile(string url, string filename) throws clientprotocolexception, ioexception{ httpget httpget = new httpget(url); httpresponse response = httpclient.execute(httpget); httpentity entity = response.getentity(); if (entity != null) { long len = entity.getcontentlength(); inputstream = entity.getcontent(); fileoutputstream fos = new fileoutputstream(new file(filepath))); ioutils.copy(is, fos); } return; }
Comments
Post a Comment