AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Simple reading HTML from a URL problem

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
XMLSDK
Guest





PostPosted: Thu Apr 29, 2004 4:31 pm    Post subject: Simple reading HTML from a URL problem Reply with quote



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);
}
}
}
}


Back to top
Fahd Shariff
Guest





PostPosted: Fri Apr 30, 2004 8:28 am    Post subject: Re: Simple reading HTML from a URL problem Reply with quote



Try:

.....
URL url = new URL("http://www.pru.com.hk/");
URLConnection urlConn = url.openConnection();

//ADD THIS LINE:--------->
urlConn.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible;
MSIE 5.5; Windows NT 5.0; H010818)" );
......

Hope it works!

Fahd
http://www.fahdshariff.cjb.net


"XMLSDK" <xmlsdk (AT) yahoo (DOT) com.hk> wrote

Quote:
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);
}
}
}
}

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.