• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to implement a Web Client to capture the "response"

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write a web client (running as a servlet), that sends a request to a remote server and then captures the response, parse the response body for relevant data, and then move on to another page.
I had implemented this in the past by writing a web-client in ASP/"Perlscript". Where the Perscript sends the "request" to the remote server, and then parses the "response" at leisure. A sample code is below.
Any suggestions how I could implement the same in the Servlet world?
example from the past:
----------
file: responseParser.asp
----------
<%@LANGUAGE="PERLSCRIPT"%>
<%
use HTTP::Request::Common qw(POST);
use HTTP::Request::Common qw(GET);
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $varURL = "http://www.cnn.com";
my $res = $ua->request( POST $varURL );
$_ = $res->{_content};
#NOTE: $_ has all the content of the response body
my $dataFound;
if ( /Interstingdata\"(.*?)\"End/s ){
$dataFound = $1;
}
$Response->Write( "found your data: " .$dataFound. "<br>" );
%>
 
domestique jackson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe the greenhorn should ask a more specific question:
How do I capture the "response" body, so that I can parse it? (remember I am the client)
 
domestique jackson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It only helps to RTFM
I believe the following solution will do the trick:
java.net.URL remoteUrl= new URL("remote_url");
java.net.URLConnection remoteConn = remoteUrl.openConnection();
DataInputStream inStream = new DataInputStream(remoteConn.getInputStream());
... so on and so on.
Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic