I am trying to read from a password-protected URL by creating a Java URL object and using corresponding stream objects and read methods. I was successful while using MATLAB 6.5.1 (R13SP1), but the server returns an error in MATLAB 7.0 (R14).
I execute the following statements:
url = java.net.URL(my_url_str); % my_url_str is the URL I am connecting to
is = url.openStream;st = java.io.InputStreamReader(is);br = java.io.BufferedReader(st);line = br.readLinewhile(~isempty(line)) line = br.readLineend
Part of the error output returned by the server upon making several calls to readLine follows:
<html><head> <title>401 Authorization Required</title> </head><body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> ...
I noticed that the type of the input stream object, determined by the following command
class(is)
is ice.net.HttpMessage$MarkerInputStream. In MATLAB 6.5.1 (R13SP1), it was sun.net.www.protocol.http.HttpURLConnection$HttpInputStream, which is the class I intend to use.
It appears that MATLAB is accessing some libraries other than the SUN (TM) Java libraries for creating and handling HTTP streams for URL objects.
Best Answer