urlwrite with http authentication
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (2개)
Guillaume
2015년 1월 28일
I don't think it's possible using urlwrite, but the weboptions of the newish websave allows you to specify username / password.
댓글 수: 19
Guillaume
2015년 2월 4일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Downloads에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!