Re: Html download challenge



"Andrea Desole" <news@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:d3c7b$42c3fe4d$d468cb3c$2771@xxxxxxxxxxxxxxxxxxxxxxx

> I find it hard to believe it doesn't work.
> Maybe I'll try later on with a Java application

Here is some sample code. You will see me loading from 2 urls. The first one
works. The second (the one I care about) does not even though my browser
(Internet Explorer) has no trouble with the url.

I get this error:

Exception in thread "main" java.io.IOException: Server returned HTTP
response co
de: 403 for URL: http://www.google.com/search?q=business
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
at java.net.URL.openStream(Unknown Source)
at SimpleTest.loadPage(SimpleTest.java:14)
at SimpleTest.main(SimpleTest.java:30)

If you can see something simple that I'm doing wrong, that would be great.

// -------------------- program begins

import java.net.*;
import java.io.*;

public class SimpleTest {

public String loadPage(String webAddr) throws Exception {
String inputLine;
BufferedReader in;
URL targetUrl;

targetUrl = new URL(webAddr);
StringBuffer htmlString = new StringBuffer();

in = new BufferedReader( new InputStreamReader(
targetUrl.openStream()));

while ((inputLine = in.readLine()) != null) {
htmlString.append(inputLine);
}

return htmlString.toString();

}

static public void main(String[] args) throws Exception {
SimpleTest test = new SimpleTest();

System.out.println("----------------------------------------------");
System.out.println(test.loadPage("http://google.com";));
System.out.println("----------------------------------------------");

System.out.println(test.loadPage("http://google.com/search?q=business";));

}
}

// ------------ program ends


.



Relevant Pages

  • RE: Detailed ASP.Net info not displaying in browser
    ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.xml)
  • RE: Detailed ASP.Net info not displaying in browser
    ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.xml)
  • Re: App_data - ASPNETDB.MDF
    ... is only because I want my site work, without exception. ... Server Error in '/' Application. ... serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Could not load file or assembly...
    ... The problem shows when EL exception handling ... context, ExceptionHandlerData objectConfiguration, IConfigurationSource ... configurationSource, ConfigurationReflectionCache reflectionCache) ... context, String name, IConfigurationSource configurationSource, ...
    (microsoft.public.dotnet.framework)
  • Re: Error handling not working
    ... Dim exception As Exception = Server.GetLastError.GetBaseException ... Dim ErrorString as String ... GetBaseException retrieves the "real" innerException object. ... CustomErrors in my webconfig file: ...
    (microsoft.public.dotnet.framework.aspnet)