Hello,
I wanna make a Login on a web page, but get this error code.
import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class Test{
private static final String LOGIN_PAGE = "...";
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
GetMethod getMethod= new GetMethod(LOGIN_PAGE);
vLoginPage.getParams().setCookiePolicy(
CookiePolicy.BROWSER_COMPATIBILITY);
client.executeMethod(getMethod);
vLoginPage.setFollowRedirects(false);
PostMethod postMethod1 = new PostMethod(
"...");
postMethod1.addParameter("username", "...");
postMethod1.addParameter("passwd", "..");
postMethod1.addParameter("target","..");
client.executeMethod(postMethod1);
System.out.println(postMethod1.getStatusCode());
String redirectLocation = null;
Header locationHeader = postMethod1.getResponseHeader("location");
if (locationHeader != null) {
redirectLocation = locationHeader.getValue();
System.out.println(redirectLocation);
} else {
// The response is invalid and did not provide the new location for
// the resource. Report an error or possibly handle the response
// like a 404 Not Found error.
}
//
}
}
Does anyone hava an idea how to solve this problem?