UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2003-08-25 09:36 PM

angoyal
Member
Registered: 2003-05-23
Posts: 31

Re: java question

I am a Java noob, so please be patient with me.

After calling getContent, I still do not have the data :(

String data = null;
Object obj = null;

URL ebayURL = new URL("http", "www.google.com",	80, "index.html");
System.out.println("ebayURL.toString(): " + ebayURL.toString());
System.out.println("ebayURL.toExternalForm(): " + ebayURL.toString());

obj = ebayURL.getContent();

System.out.println("obj: " + obj.toString() );

this is the output I get

ebayURL.toString(): [url]http://www.google.com:80index.html[/url]
ebayURL.toExternalForm(): [url]http://www.google.com:80index.html[/url]
obj: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@a0dcd9

what do I have to do to get the HTML text?

Offline

#2 2003-08-25 10:10 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,826
Website

Re: java question

Disclaimer: I know absolutely NOTHING about Java... ;-)
However, just by looking at that printed URL of yours, I'm going
to say you want "/index.html" (or, simply "/" should suffice),
rather than "index.html"...

Offline

#3 2003-08-27 06:42 AM

angoyal
Member
Registered: 2003-05-23
Posts: 31

Re: java question

I tried your suggestion

ebayURL.toString(): http://www.google.com:80/index.html
ebayURL.toExternalForm(): http://www.google.com:80/index.html
obj: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1eed786

anyone else here a java expert? does anyone else know of other forums where people may have more advice?  Don't get me wrong, I like this forum, but I need the answer to this question soon!

Offline

#4 2003-08-31 09:41 PM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: java question

Since you are calling getContent and storing the return into an Object type, the call to print is simply outputting it's (the Object class object ~ wow, that sounds confusing... lol) info...  this is a simple Object's default behaviour...

Try casting the return from the getContent call to a String type... and storing it in a String object... then do your printout...

Same idea for other data types...  i.e. if you are pulling down more complex types of data... cast... then display...  in some cases, you may have to make your own (new) data types to handle the content...

Michael


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

#5 2004-01-20 06:57 AM

refernet
Guest

Re: java question

You should cast the content object into a StringBuffer and use an iterator to read it line by line.

Cheers,
Jeff

angoyal wrote:

I am a Java noob, so please be patient with me.

After calling getContent, I still do not have the data :(

String data = null;
Object obj = null;

URL ebayURL = new URL("http", "www.google.com",	80, "index.html");
System.out.println("ebayURL.toString(): " + ebayURL.toString());
System.out.println("ebayURL.toExternalForm(): " + ebayURL.toString());

obj = ebayURL.getContent();

System.out.println("obj: " + obj.toString() );

this is the output I get

ebayURL.toString(): [url]http://www.google.com:80index.html[/url]
ebayURL.toExternalForm(): [url]http://www.google.com:80index.html[/url]
obj: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@a0dcd9

what do I have to do to get the HTML text?

#6 2004-04-15 06:11 AM

aukahi
Member
From: Honolulu
Registered: 2004-04-14
Posts: 14

Re: java question

for webpages, you don't use getContent().  getContent() is used for non text/html or text/plain type of contents from the internet.

instead, why don't you just use the openStream() method of URL class and then you can read from the InputStream object.

Offline

Board footer

Powered by FluxBB