Re: Html download challenge
- From: "Paul Battersby" <batman42ca@xxxxxxxx>
- Date: Thu, 30 Jun 2005 11:10:28 -0400
"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
.
- Follow-Ups:
- Re: Html download challenge
- From: Patrick May
- Re: Html download challenge
- From: Andrea Desole
- Re: Html download challenge
- References:
- Html download challenge
- From: Paul Battersby
- Re: Html download challenge
- From: Andrea Desole
- Re: Html download challenge
- From: Paul Battersby
- Re: Html download challenge
- From: Andrea Desole
- Html download challenge
- Prev by Date: Re: enum aliases
- Next by Date: In praise of Java 1.5 enums
- Previous by thread: Re: Html download challenge
- Next by thread: Re: Html download challenge
- Index(es):
Relevant Pages
|