| Author |
How to implement a Web Client to capture the "response"
|
domestique jackson
Greenhorn
Joined: Aug 29, 2002
Posts: 10
|
|
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
Joined: Aug 29, 2002
Posts: 10
|
|
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
Joined: Aug 29, 2002
Posts: 10
|
|
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.
|
 |
 |
|
|
subject: How to implement a Web Client to capture the "response"
|
|
|