Results 1 to 1 of 1
Thread: httpclient athentification issue
- 09-30-2010, 09:03 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 4
- Rep Power
- 0
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();
}
}
}
Similar Threads
-
httpClient API to Download a xls file.
By mpahlenig in forum New To JavaReplies: 1Last Post: 01-13-2010, 03:31 AM -
Using HttpClient
By jdetloff in forum New To JavaReplies: 4Last Post: 01-06-2010, 10:43 AM -
Using HttpClient with Eclipse
By jdetloff in forum EclipseReplies: 4Last Post: 01-06-2010, 09:47 AM -
Getting httpclient working with eclipse.
By int80 in forum EclipseReplies: 4Last Post: 03-31-2009, 01:17 PM -
HttpClient invalid headers
By Nicole in forum Advanced JavaReplies: 6Last Post: 03-31-2009, 12:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks