File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read from a URL

 
Trista Lau
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, I'm trying to get the text of this URL in Java:
https://www.lcsd.gov.hk/en/forms_lcs71_online.php?act_code=40216827
Then I wrote the code like this:
try{
URL url = new URL("https://www.lcsd.gov.hk/en/forms_lcs71_online.php?act_code=40216827");
}catch ...

It failed as URL class cannot recognize the filename The following variables of the URL are as follows:
------------------------------------------------------------------------
protocol = https
authority = www.lcsd.gov.hk
host = www.lcsd.gov.hk
port = -1
path = b5/forms_lcs71_online.php
query = act_code=40216827
filename = b5/forms_lcs71_online.php?act_code=40216827
ref = null
-------------------------------------------------------------------------
Could anyone suggest me a way to read a URL that is not ended with file extensions (.html, .txt....)?
Thank you.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I clicked the URL and Firefox pointed out the self-signed certificate -- i.e., the https installation is suspect. I don't know if that's what's giving you problems, or if you just haven't taken the necessary steps to handle https in general. See here for details about that.

In any case, it has nothing to do with "recognizing the filename" -- the format of the part of the URL after the server name is irrelevant. It's up to the server to understand it, not your code.
 
Trista Lau
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your instant and helpful reply.

Yes, the URL I need to get is a web form provided by the government for citizens to apply courses.
The form needs authentication for security. And, an exception is caught.

In the article you give to me, Java Tip 96: Use HTTPS in your Java client code(Page 2),
"What about applets?
Performing HTTPS-based communication from within an applet seems like a natural extension of scenarios described above. In reality, it's even easier in most cases. In 4.0 and later versions of Netscape Navigator and Internet Explorer, HTTPS is enabled by default for their respective VMs. ... simply specify HTTPS as your protocol when creating an instance of the URL class:
URL url = new URL("https://[your server]");"

Does it mean if I write an Applet, instead of Java Application, I need not worry about https?

I think https protocol can be understood by Java URL class.
But, what I worry is the red part cannot be understood:
https://www.lcsd.gov.hk/en/forms_lcs71_online.php?act_code=40216827
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, the red part is completely ignored by your Java code.

Why not tell us the actual error message you're receiving?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic