By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

A programme to receive the HTML code from a URL

P: n/a
I have written a programme to receive the HTML code from a URL
http://www.pru.com.hk/
But I dunno why it doesn't work. It can only receive the beginning few
lines:

<!-- i n clude file="BB.asp" -->

And the remaining cannot be obtained. Can anyone help me with this problem?
Thank you.
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class App {

public static void main(String[] args) {
BufferedReader br = null;
try
{
URL url = new URL("http://www.pru.com.hk/");
URLConnection urlConn = url.openConnection();
InputStreamReader isr = new InputStreamReader(urlConn.getInputStream());
br = new BufferedReader(isr);

String str;
while ((str = br.readLine()) != null)
{
System.out.println(str);
}
}
catch (IOException e)
{
System.err.println(e);
}
finally
{
try
{
if (br != null) br.close();
}
catch (IOException e)
{
System.err.println(e);
}
}
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
XMLSDK wrote:
I have written a programme to receive the HTML code from a URL
http://www.pru.com.hk/
But I dunno why it doesn't work. It can only receive the beginning few
lines:

<!-- i n clude file="BB.asp" -->

And the remaining cannot be obtained. Can anyone help me with this problem?
Thank you.
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class App {

public static void main(String[] args) {
BufferedReader br = null;
try
{
URL url = new URL("http://www.pru.com.hk/");
URLConnection urlConn = url.openConnection();
InputStreamReader isr = new InputStreamReader(urlConn.getInputStream());
br = new BufferedReader(isr);

String str;
while ((str = br.readLine()) != null)
{
System.out.println(str);
}
}
catch (IOException e)
{
System.err.println(e);
}
finally
{
try
{
if (br != null) br.close();
}
catch (IOException e)
{
System.err.println(e);
}
}
}
}


My guess would be that the response is encoded in a character set
different from the default character set on your system. Try reading
the response as a binary stream and same it to a file and see if the
results differ.

Ray
Jul 17 '05 #2

P: n/a
Liz
there are lots of examples around on the web
just waiting for you to search for them
"Raymond DeCampo" <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in
message news:A0*******************@twister.nyroc.rr.com...
XMLSDK wrote:
I have written a programme to receive the HTML code from a URL
http://www.pru.com.hk/
But I dunno why it doesn't work. It can only receive the beginning few
lines:

<!-- i n clude file="BB.asp" -->

And the remaining cannot be obtained. Can anyone help me with this problem? Thank you.
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class App {

public static void main(String[] args) {
BufferedReader br = null;
try
{
URL url = new URL("http://www.pru.com.hk/");
URLConnection urlConn = url.openConnection();
InputStreamReader isr = new InputStreamReader(urlConn.getInputStream()); br = new BufferedReader(isr);

String str;
while ((str = br.readLine()) != null)
{
System.out.println(str);
}
}
catch (IOException e)
{
System.err.println(e);
}
finally
{
try
{
if (br != null) br.close();
}
catch (IOException e)
{
System.err.println(e);
}
}
}
}


My guess would be that the response is encoded in a character set
different from the default character set on your system. Try reading
the response as a binary stream and same it to a file and see if the
results differ.

Ray

Jul 17 '05 #3

P: n/a
Could it be a timeout while reading response?

Perhaps you would like to try HttpClient as well. It takes care of
many aspects while connecting to a site, worth taking a look at it =)

"XMLSDK" <xm****@yahoo.com.hk> wrote in message news:<40********@rain.i-cable.com>...
I have written a programme to receive the HTML code from a URL
http://www.pru.com.hk/
But I dunno why it doesn't work. It can only receive the beginning few
lines:

<!-- i n clude file="BB.asp" -->

And the remaining cannot be obtained. Can anyone help me with this problem?
Thank you.
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class App {

public static void main(String[] args) {
BufferedReader br = null;
try
{
URL url = new URL("http://www.pru.com.hk/");
URLConnection urlConn = url.openConnection();
InputStreamReader isr = new InputStreamReader(urlConn.getInputStream());
br = new BufferedReader(isr);

String str;
while ((str = br.readLine()) != null)
{
System.out.println(str);
}
}
catch (IOException e)
{
System.err.println(e);
}
finally
{
try
{
if (br != null) br.close();
}
catch (IOException e)
{
System.err.println(e);
}
}
}
}

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.