Please could someone help me. Why does the following code not work? It keeps reloading the same page instead of going on to the next page.
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class PostTest {
public static void main( String[] args ) {
String url = " try {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod( url );
method.setDoAuthentication(true);
// Configure the form parameters
method.addParameter( "login", "myuserid");
method.addParameter( "passwd", "mypassword" );
// Execute the POST method
int statusCode = client.executeMethod( method );
if( statusCode != -1 ) {
String contents = method.getResponseBodyAsString();
File name = new Fil("C:/project/test.html");
FileWriter fw = new FileWriter(name);
try {
fw.write(contents);
} catch (IOException e) {
}
method.releaseConnection();
fw.close();
}
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class PostTest {
public static void main( String[] args ) {
String url = " try {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod( url );
method.setDoAuthentication(true);
// Configure the form parameters
method.addParameter( "login", "myuserid");
method.addParameter( "passwd", "mypassword" );
// Execute the POST method
int statusCode = client.executeMethod( method );
if( statusCode != -1 ) {
String contents = method.getResponseBodyAsString();
File name = new Fil("C:/project/test.html");
FileWriter fw = new FileWriter(name);
try {
fw.write(contents);
} catch (IOException e) {
}
method.releaseConnection();
fw.close();
}
}
catch( Exception e ) {
e.printStackTrace();
}
}
}