0

The task at hand is to login to a website and download a report using MATLAB. I cannot find anything helpful on the subject. I have written code to do this in VB before using WinHTTPRequest but even that hasn't helped in MATLAB.

Any pointers, examples or guidance would be much appreciated.

I have the code in VBA already and its very complicated so the best way to go about this was to translate VBA to MATLAB. I used x = actxserver( 'WinHttp.WinHttpRequest.5.1' ) to make the HTTP requests. All has worked apart from x.Option(WinHttpRequestOption_EnableRedirects) = enableRedirect, where enableRedirect is true. I have tried the following with no luck:

WinHttpRequestOption_EnableRedirects = 6;
set( x, 'Option', WinHttpRequestOption_EnableRedirects, enableRedirect );
x.set('Option',WinHttpRequestOption_EnableRedirects,enableRedirect);
x.set('Option',6,enableRedirect);

Has anyone ever managed to set this option in Matlab?

user1323670
  • 71
  • 1
  • 2
  • 10
  • Why would you use MATLAB for that? Why not something more appropriate, like Python? – Eitan T Jul 18 '12 at 09:44
  • @EitanT Unfortunately I am required to use Matlab for this as all other users know Matlab and nothing else. As I mentioned, I have already written code for this in VB & VBA, which the users cannot debug or modify. – user1323670 Jul 26 '12 at 16:27

3 Answers3

1

Matlab has functions urlread and ftp which look likely to be good starting points for you. As ever, read the documentation.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
0

If it's more complicated Java methods can be directly used within matlab.

eg. suggestion How do I retrieve a URL from a web site using Java?

would look like this in Matlab:

url = java.net.URL('http://example.com')
connection   = url.openConnection
connection.setRequestMethod('GET')
connection.connect()
stream = connection.getInputStream()

practically the same - isn't it? For sure you will find in Java the methods for authentication.

Community
  • 1
  • 1
bdecaf
  • 4,652
  • 23
  • 44
0

I used the following code:

x = actxserver( 'WinHttp.WinHttpRequest.5.1' );
x.Open(sType, sUrl, false);
if strcmp( sType,'POST');
    x.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
else
    x.SetRequestHeader('Content-Type', 'text/html')
end

x.SetRequestHeader('If-Modified-Since', 'Jan 1 2000 00:00:00 UTC' );
x.SetRequestHeader('Pragma', 'no-cache' );

if ~isempty( sCookie )
    x.SetRequestHeader('Cookie', sCookie);
end
x.SetRequestHeader('Accept-Language', 'en-gb');
x.SetRequestHeader('Connection', 'Keep-Alive');
x.SetRequestHeader('Accept', '*/*');
x.SetRequestHeader('UA-CPU', 'x86');
x.Send (sSoap)
writeStringToFile(sFileNameAndPath, x.responseText, true);
user1323670
  • 71
  • 1
  • 2
  • 10