aspose file tools*
The moose likes I/O and Streams and the fly likes Read from a URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read from a URL" Watch "Read from a URL" New topic
Author

Read from a URL

Trista Lau
Greenhorn

Joined: Jan 18, 2010
Posts: 2
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Trista Lau
Greenhorn

Joined: Jan 18, 2010
Posts: 2
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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
 
subject: Read from a URL