When parsing a webpage, I get the link href=http://www.onvista.de/aktien/snapshot.html?ID_OSI=36714349 When issuing this link in my browser, it replaces it with "http://www.onvista.de/aktien/Adidas-Aktie-DE000A1EWWW0" and renders it correctly. But with java I fail to retrieve the page. I used the following sample which was suggested here to display redirected URLs.
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class GetRedirected {
public GetRedirected() throws MalformedURLException, IOException {
String url="http://www.onvista.de/aktien/snapshot.html?ID_OSI=36714349";
URLConnection con = new URL( url ).openConnection();
System.out.println( "orignal url: " + con.getURL() );
con.connect();
System.out.println( "connected url: " + con.getURL() );
InputStream is = con.getInputStream();
System.out.println( "redirected url: " + con.getURL() );
is.close();
}
public static void main(String[] args) throws Exception {
new GetRedirected();
}
}
But it fails at the "InputStream is ="-statement with the attached error message. How may I solve this. Any idea is welcome.
orignal url: www.onvista.de/aktien/snapshot.html?ID_OSI=36714349
connected url: www.onvista.de/aktien/snapshot.html?ID_OSI=36714349
Exception in thread "main" java.io.IOException: Server returned HTTP
response code: 403 for URL: www.onvista.de/aktien/snapshot.html?ID_OSI=36714349
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at de.gombers.broker....