Domanda

I'm trying to get a vbscript to return the name of a file offered from a URL. For instance, in a browser this address will try to start the download for the latest version of Java JRE:

http://javadl.sun.com/webapps/download/AutoDL?BundleId=86895

My script uses MSXML2.ServerXMLHTTP.6.0 to send a "GET" request and then ADODB.Stream to write the file but what kind of request would I want to send to verify the file's name before sending the "GET" request?

A browser is smart enough to identify the file name as jre-7u55-windows-i586.exe so I'm guessing VBS should able to as well.

Thanks in advance.

Update:

A bit more searching revealed I probably want GetResponseHeader. I've tried using this but it just comes back blank everytime:

url      = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=86895" 
Set req = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
req.open "GET", url, False 
req.send() 
wscript.echo req.GetResponseHeader("Content-Disposition")

I think I'm making progress but I'm clearly missing something.

Update #2

It looks like the above URL is actually redirected here:

http://sdlc-esd.sun.com/ESD6/JSCDL/jdk/7u55-b13/jre-7u55-windows-i586.exe?AuthParam=1398824389_144b5eeb1ec36ffe8bab22613453d40b&GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/7u55-b13/jre-7u55-windows-i586.exe&File=jre-7u55-windows-i586.exe&BHost=javadl.sun.com

I looked at the header response from this URL and the only place the file name appears is in the URL File=jre-7u55-windows-i586.exe

Since the file name doesn't exist within the response header, do browsers just know to pick out things like File=whatever.exe as the name of the file when the browser offers to have you Save or Open it?

As it stands I can just parse the redirect URL and pull out the file name from there but that seems a pretty ugly solution.

È stato utile?

Soluzione

The browser takes the last path segment as default name (so just remove the query part and look for the last slash).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top