File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
domestique jackson
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic