I want to download the file associated to an url which is an http request to download a file
The url can be anything, just i know the final answer of the server will be a file, it can be any type and could have any name. I want to write a method with a signature like this:
public String saveUrl(String url, String outputDir){
//something here
return file.getCanonicalPath();
}
Example:
url="http://domain.com/?someparameter=somevalue",
outputDir="C:\"
returned="C:\myFile.myExtension"
Here How to download and save a file from Internet using Java? is very explicit about how to download a file. Just one problem. All methods specified requiers we give the target String Filename o target File object, but i want to obtain name from the http request, how to acomplish that?
Just for an example, i would like to feed the method with this: https://demo.xsa.com.mx/xsamanager/downloadCfdWebView?serie=CARS&folio=20&tipo=XML&rfc=TUNO700901493&key=4585d3f7518f5ffa062fa4e3b4e64831
and get the xml output with the name given for the server.
Any help?
Thanks in advance