• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

httpclient athentification issue

 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. Please don't pay attention to the url mistake and correct it easily if you wan't to give a try...



[NK] Please UseCodeTags
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I go to that site it looks like it uses form-based authentication. That isn't supported by the authentication protocols in HttpClient. You're going to have to pass suitable parameters (i.e. whatever parameters the form asks for) in your POST request.
 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well...... now I'm a bit embarassed cause I didn't read that httpclient did not handle this auth method... then that's really true that the website uses a post method so I just need to use something like :

HttpClient client = new HttpClient();
client.getParams().setParameter("id", "pass");



PostMethod method = new PostMethod("url");


?? thanks for the help
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's right. It might be a bit more complicated than that but you can work out the details as you go along.
 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks so I tried this with no luck, still ending up on the login page:



[NK] Please UseCodeTags
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you sending the user ID's value? Or the password? I don't see any of that.

Also, keep in mind that HTTP is essentially a stateless protocol. Cookies and sessions are a way around that, so you may want to use the cookies set by the original request in all following requests.
 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I confess that I'm quite new java and I thought I was sending the id by the writer.write(encodedData); so am I offending the java's god by this sentence ??
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's sending the parameter name UserID, but no value, nor the password. You should send it as "UserID=xxx&password=yyy". But if you use HttpClient, you can use PostMethod and its addParameter methods.
 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your answer. In fact, there is no need of any password so what i meant by userid in the code ex would be replaced in by the real userid but I guess I should use "UserID=xxx" right ?
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how the user ID field is named on the website. It might be UserID, user, uid or anything similar. You'll have to check that out first.
 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks, I tried to lo on another webpage (https) which has the same kind of form with a javascript validation. I used httpclient and get a message "other session running" as a response. Here is the code, it seems to go a bit further :

 
Alex Ter
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any hint??... I'm quite stuck thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic