1

I am trying to autologin into a webpage. Im asssuming that i pass the proper credentials.

entity.getContentLength() shows 20 but the repsonse i see is not well formatted. It is not an HTML. How should i proceed further. Below is my code.

String input_text = "https://www.abc.com";
                HttpPost httpost = new HttpPost(input_text);

                List <NameValuePair> nvps = new ArrayList <NameValuePair>();
                nvps.add(new BasicNameValuePair("email", "abc@xyz.com"));
                nvps.add(new BasicNameValuePair("passsword", "ttyyeri"));   
                nvps.add(new BasicNameValuePair("publicLoginToken",""));

                httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

                HttpResponse  response = httpclient.execute(httpost);
                entity  = response.getEntity();

                if (entity != null) {
                  BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
                  String readLine;
                  while(((readLine = br.readLine()) != null)) {
                    System.err.println("br   :"+readLine);
                 }
                  System.out.println("Response content length: " + entity.getContentLength());

                }      

                System.out.println("HTML Content :::"+entity.getContent().toString());
Geek
  • 3,187
  • 15
  • 70
  • 115
  • `It is not an HTML` than what it is.? – RanRag Feb 07 '12 at 21:28
  • Can you post the response you are getting back? – nolt2232 Feb 07 '12 at 21:31
  • @ranRag..the repsonse is not in an HTML format. the above System.err.println("br :"+readLine); prints somehting which is not formatted. I am not able to copy paste the response...looks like this...br :‹. – Geek Feb 07 '12 at 21:32
  • @javaiText : http 302 means redirection.You need to set a http referer. Use `firefox's live http header` addon to see what actually happens when you login manually. – RanRag Feb 07 '12 at 21:52
  • how do i set http referer? When i monitored the live HttpHeader, the above v3/credential url has Referer: https://www.hautelook.com/login. What does it mean? any examples that might help? – Geek Feb 07 '12 at 22:14

3 Answers3

1

try

  StatusLine l = response.getStatusLine();
  System.out.println(l.getStatusCode() + "  " + l .getReasonPhrase());

output ?

  • httpGet gives me a HTML repsonse of the 'New Member login page' – Geek Feb 07 '12 at 22:11
  • a looked at the page - they are sending data in JSON format {"email":"sdasd","password":"asdas","meta":{"screen_resolution":{"height":768,"width":1366}}} –  Feb 07 '12 at 22:17
  • So i need to create a JASON object and pass the credentials in that manner?a – Geek Feb 07 '12 at 22:27
0

Sounds like you are getting an authorization request redirect. This may have already been covered here: Http Basic Authentication in Java using HttpClient?

Community
  • 1
  • 1
dbrin
  • 15,525
  • 4
  • 56
  • 83
0

Investigate the HttpResponse Header, you can find the content type and the response code. Which will help you to find the problem.

Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38