Sunday 15 September 2013

Calling Web-Service / Website from Java -


Writing some extra classes for an existing GWT project I need it:

  • A URL Request for
  • Read back in the webpage to perform the operation.

The back page is in very simple HTML, so parsing should not be difficult, I must first get the data.

How can I do this in Java? With the original Java API you can read using a URL. I / O

Here's a basic example:

  URL url = New URL ("http://www.stackoverflow.com"); URL Connection URL Connection = url.openConnection (); InputStream results = urlConnection.getInputStream (); BufferedReader Reader = New BufferedReader (New InputStreamReader (Results)); String line = null; While ((line = reader.readline ()) = null {} System.out.println (line); } Reader.close ();  

You can feed any DOM / SAX parser to your taste by InputStream . The average parser can take a InputStream argument as straight. One of the better HTML Parsons is.

: //www.stackoverflow.com ") .openStream ();

No comments:

Post a Comment