Help with IDLnetURL [message #85212] |
Sun, 14 July 2013 08:05  |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
All,
I am trying to use the IDLnetURL class to retrieve data from an HTTP site. The documentation on the host says it will return either a Zip file containing the data or a Text file named CAA_Error.log.x, depending on whether an error occurred or not. The problem is that IDL changes the filename of the saved file to 'idl.dat', or to whatever I specify with the FILENAME keyword. Is there any way to determine which file type has been retrieved and to name it accordingly?
The scheme they give is this:
url = ' http://caa.estec.esa.int/caa_query/?key1=value1&key2=val ue2&...'
So, what I am doing is:
oURL = Obj_New('IDLnetURL')
oURL -> SetProperty, URL_SCHEME='http', URL_HOST='caa.estec.esa.int'
[Widget to get input from user (i.e. username, password, etc.)]
oURL -> SetProperty, URL_PATH='caa_query/?key1=value1&key2=value2&...'
fname_returned = oURL -> Get()
|
|
|
Re: Help with IDLnetURL [message #85226 is a reply to message #85212] |
Wed, 17 July 2013 07:58   |
Rob Klooster
Messages: 18 Registered: February 2013
|
Junior Member |
|
|
Op zondag 14 juli 2013 17:05:51 UTC+2 schreef Matthew Argall het volgende:
> All,
>
>
>
> I am trying to use the IDLnetURL class to retrieve data from an HTTP site. The documentation on the host says it will return either a Zip file containing the data or a Text file named CAA_Error.log.x, depending on whether an error occurred or not. The problem is that IDL changes the filename of the saved file to 'idl.dat', or to whatever I specify with the FILENAME keyword. Is there any way to determine which file type has been retrieved and to name it accordingly?
>
>
>
> The scheme they give is this:
>
> url = ' http://caa.estec.esa.int/caa_query/?key1=value1&key2=val ue2&...'
>
>
>
> So, what I am doing is:
>
>
>
> oURL = Obj_New('IDLnetURL')
>
> oURL -> SetProperty, URL_SCHEME='http', URL_HOST='caa.estec.esa.int'
>
>
>
> [Widget to get input from user (i.e. username, password, etc.)]
>
>
>
> oURL -> SetProperty, URL_PATH='caa_query/?key1=value1&key2=value2&...'
>
>
>
> fname_returned = oURL -> Get()
You could save a temporary copy, read in the first couple of bytes from the file and compare it to the magic number for ZIP files (see http://www.digitalpreservation.gov/formats/fdd/fdd000354.sht ml under file signatures)
bytes = bytarr(4)
openr, lun, filename, /get_lun
readu, lun, bytes
free_lun, lun
If the bytes array is equal to [80b,75b,1b,2b], [80b,75b,3b,4b], [80b,75b,5b,6b] or [80b,75b,7b,8b] then it is a ZIP file, otherwise it is probably the plain text file.
|
|
|
|
|
|