httpclient athentification issue
Hi guys, I have an issue to login to a website with a simple form login.
My code always returns website login page despite the fact that all the parameters are correct and I'm trying to access to a home page. I'm using the classic AuthScope.ANY method.
thanks for your help.
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodPar ams;
import org.apache.commons.httpclient.UsernamePasswordCred entials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import java.io.*;
class ConnectIntellio1 {
private static String url = "intellio.fr/extranet/index.ph)";
public static void main(String[] args) {
HttpClient client = new HttpClient();
/* client.getParams().setParameter("tWary", "pass");
PostMethod method = new PostMethod(url);*/
client.getState().setCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials("XXX",null ) //PWPGJPO076
);
GetMethod method = new GetMethod(url);
method.setDoAuthentication(true);
method.getParams().setParameter(HttpMethodParams.R ETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}
//ConnectIntellio2 connec = new ConnectIntellio2();
InputStream responseBody = method.getResponseBodyAsStream();
File f=new File("outFile.html");
BufferedOutputStream out=new BufferedOutputStream( new FileOutputStream(
f.getName() ) );
byte buf[]=new byte[1024];
int len;
while((len=responseBody.read(buf))>0)
out.write(buf,0,len);
out.close();
responseBody.close();
System.out.println("Fichier créé");
} catch (Exception e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} finally {
method.releaseConnection();
}
}
}