I am writing a personal Java application that will allow me to view  
financial balances posted on a web site.  To view the site with my  
Firefox browser, I do the following:

1) I paste the URL: https://isc.nwservicecenter.com/iApp/isc/cmd/Login  
into my "URL bar"

2) The browser takes me to the Logon page

3)  I enter my "username" and "password" and either click on a "Go" button or 
press  the Enter key on my keyboard.

4) The browser takes me to  
https://isc.nwservicecenter.com/iApp/isc/cmd/AppLogic+IAAcctSummary  
where I view my account summary
 
Firefox handles all cookies automatically.
 
I have written a Java application, modeled after the  HttpClientTutorial, 
that I think should do the same thing, but, so far at  least, it does not.  The 
program seems able to connect with the URL in  step 1).  It also seems to send 
my "username" and "password" using a  POST.  However, the printout of the 
responseBody shows the html code  of the Login page rather than the page 
showing 
the account summary in step  4).  The commented code listing of my HttpClient 
application is as  follows.
 
import org.apache.commons.httpclient.*;
import  org.apache.commons.httpclient.methods.*;
import  org.apache.commons.httpclient.cookie.*;
import java.io.*;
 
public class HttpClientTutorial2 {

private static  String url = 
"_https://isc.nwservicecenter.com/iApp/isc/cmd/Login_ 
(https://isc.nwservicecenter.com/iApp/isc/cmd/Login) ";
 
  public static void main(String[] args) {
//  Create an instance of HttpClient.
HttpClient client = new  HttpClient();
//Set Cookie Policy
HttpMethod  cookieMethod = new GetMethod();
cookieMethod.getParams().setCookiePolicy("BROWSER_COMPATIBLE");

//  Create a PostMethod method instance.
 
 PostMethod method = new  PostMethod(url);
NameValuePair[]  data = {
new  NameValuePair("username",  "xxxxxxx"),
new  NameValuePair("password",  "yyyyyy")
};

try {
//  Execute the method.
int statusCode =  client.executeMethod(method);
 
      if (statusCode != HttpStatus.SC_OK)  {
System.err.println("Method  failed: " + method.getStatusLine());
}
 
      // Read the response  body.
byte[] responseBody =  method.getResponseBody();
 
      // Deal with the  response.
System.out.println(new  String(responseBody));
 
    } catch (IOException e)  {
System.err.println("Failed to download  file.");
e.printStackTrace();
}
finally  {
// Release the  connection.
method.releaseConnection();
}
}
}





Reply via email to