Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

Simple reading HTML from a URL problem

Thread view: 
XMLSDK - 29 Apr 2004 17:31 GMT
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);
  }
 }
}
}
Fahd Shariff - 30 Apr 2004 09:28 GMT
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      

> I have written a programme to receive the HTML code from a URL
> http://www.pru.com.hk/
[quoted text clipped - 44 lines]
>  }
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.