urlwrite with http authentication

5 visualizaciones (últimos 30 días)
buer
buer el 28 de En. de 2015
Editada: buer el 4 de Feb. de 2015
Hi,
I got one problem , that with urlwrite function,can it work for http authentication also? I have checked early some people said: function has a "params" argument, but these are CGI-style parameters that get encoded in the URL. Authentication is done with lower-level HTTP Request parameters.
Here I found that Authentication option in urlwrite.m is ONLY available since Matlab release 2013a. You can check your matlab version by typing ver at the Matlab prompt. With the example
URL = 'http://csa.esac.esa.int/csa/aio/product-action';
fileName = tempname;
gzFileName = [fileName '.gz'];
[gzFileName,st] = urlwrite(URL,gzFileName, 'Authentication', 'Basic', ...
'Get', {'Username', '<username>', 'password', '<password>', ...
'DATASET_ID', 'C1_CP_WHI_ELECTRON_DENSITY', 'START_DATE', ...
'2011-11-10T18:00:00Z', 'END_DATE', '2011-11-10T21:00:00Z', ...
'NON_BROWSER', '1'});
gunzip(gzFileName);
fileNames = untar(fileName);
for iFile = 1:numel(fileNames)
disp(fileNames{iFile});
end
this gives me error all the time. Is this correct parameters?

Respuestas (2)

Guillaume
Guillaume el 28 de En. de 2015
I don't think it's possible using urlwrite, but the weboptions of the newish websave allows you to specify username / password.
  19 comentarios
Guillaume
Guillaume el 4 de Feb. de 2015
Just seen your edit to the question. The syntax of your urlwrite call is wrong. It should be
[gzFileName,st] = urlwrite(URL,gzFileName, 'Authentication', 'Basic', ...
'Username', '<username>', 'password', '<password>', ...
'Get', {'DATASET_ID', 'C1_CP_WHI_ELECTRON_DENSITY', 'START_DATE', ...
'2011-11-10T18:00:00Z', 'END_DATE', '2011-11-10T21:00:00Z', ...
'NON_BROWSER', '1'});
The reply I get (without the username / password)
LOGIN_REQUESTED http://csa.esac.esa.int/csa/aio/product-action?DATASET_ID=C1_CP_WHI_ELECTRON_DENSITY&START_DATE=2011-11-10T18%3A00%3A00Z&END_DATE=2011-11-10T21%3A00%3A00Z&NON_BROWSER=1
which is expected since I didn't supply the username/password
This won't solve the problem that you can't connect to anything at all, though.
buer
buer el 4 de Feb. de 2015
Editada: buer el 4 de Feb. de 2015
You hit the spot. The settings in my preference/Web is wrong, it was using Proxy server..Now after I took it away, it works with this.
urlread('https://www.google.com')
What is the Get parameter, also the time etc. I want to download the file which is linked in the url ... This might be the problem? I do not think I need start date and end data etc...
[gzFileName,st] = urlwrite(url,wanted_h5, 'Authentication', 'Basic', ...
'Username', '<uuuu>', 'password', '<ooo>');
But when I tried this it did not download also.
Thanks a lot , I will try to figure it out

Iniciar sesión para comentar.


Cedric
Cedric el 28 de En. de 2015
Editada: Cedric el 28 de En. de 2015
I have been using the URLREAD/WRITE_AUTH provided here, or similar, for years now.
  1 comentario
buer
buer el 28 de En. de 2015
In fact I am also using this function you mentioned. But I want to know is it possible when you login once you want to download many files, but only with one time authentication....so the username and password is in memeory...that is why I am thinking if Matlab have the already working function would be nice. Because I do not know how to handle with this ...How do you handle with this? Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Call Web Services from MATLAB Using HTTP en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by