Hi,
I want to get the content of an HTML page. I tried to use the classes URLConnection, URL, etc. from the java.net package. It seems to work but the web site from which I am trying to get the page detects that I am not an IE, Netscape user and does not allow access.
I think the solution is to setup an appropriate user agent for the request but how it could be done in Java?
Here is the code I used without the exception handlings :
URL urlMySongBook = new URL (" URLConnection connection = urlMySongBook.openConnection();
connection.setDoInput (true);
BufferedInputStream in = new BufferedInputStream (connection.getInputStream());
File fileOutput = new File ("E:\\temp\\test"
;
BufferedOutputStream out = new BufferedOutputStream (new FileOutputStream (fileOutput));
int dataRead = 0;
while (dataRead != -1)
{
dataRead = in.read ();
out.write (dataRead);
}
in.close ();
out.close ();
--
Globos
I want to get the content of an HTML page. I tried to use the classes URLConnection, URL, etc. from the java.net package. It seems to work but the web site from which I am trying to get the page detects that I am not an IE, Netscape user and does not allow access.
I think the solution is to setup an appropriate user agent for the request but how it could be done in Java?
Here is the code I used without the exception handlings :
URL urlMySongBook = new URL (" URLConnection connection = urlMySongBook.openConnection();
connection.setDoInput (true);
BufferedInputStream in = new BufferedInputStream (connection.getInputStream());
File fileOutput = new File ("E:\\temp\\test"
BufferedOutputStream out = new BufferedOutputStream (new FileOutputStream (fileOutput));
int dataRead = 0;
while (dataRead != -1)
{
dataRead = in.read ();
out.write (dataRead);
}
in.close ();
out.close ();
--
Globos