private void doFormLogin(FormAuthInfo authInfo){
  logger.info("FORM authentication for: " + authInfo.getLoginTarget());
  String fullUri=authInfo.getProtocol() + "://" + authInfo.getHost()+ ":"+ authInfo.getPort()+ authInfo.getLoginTarget();
  HttpPost httpPost=new HttpPost(fullUri);
  List<NameValuePair> formParams=new ArrayList<>();
  formParams.add(new BasicNameValuePair(authInfo.getUsernameFormStr(),authInfo.getUsername()));
  formParams.add(new BasicNameValuePair(authInfo.getPasswordFormStr(),authInfo.getPassword()));
  try {
    UrlEncodedFormEntity entity=new UrlEncodedFormEntity(formParams,"UTF-8");
    httpPost.setEntity(entity);
    httpClient.execute(httpPost);
    logger.debug("Successfully Logged in with user: " + authInfo.getUsername() + " to: "+ authInfo.getHost());
  }
 catch (  UnsupportedEncodingException e) {
    logger.error("Encountered a non supported encoding while trying to login to: " + authInfo.getHost(),e);
  }
catch (  ClientProtocolException e) {
    logger.error("While trying to login to: " + authInfo.getHost() + " - Client protocol not supported",e);
  }
catch (  IOException e) {
    logger.error("While trying to login to: " + authInfo.getHost() + " - Error making request",e);
  }
}

private void doFormLogin ( FormAuthInfo authInfo ) { logger . info ( "FORM authentication for: " + authInfo . getLoginTarget ( ) ) ; String fullUri = authInfo . getProtocol ( ) + "://" + authInfo . getHost ( ) + ":" + authInfo . getPort ( ) + authInfo . getLoginTarget ( ) ; HttpPost httpPost = new HttpPost ( fullUri ) ; List < NameValuePair > formParams = new ArrayList < > ( ) ; formParams . add ( new BasicNameValuePair ( authInfo . getUsernameFormStr ( ) , authInfo . getUsername ( ) ) ) ; formParams . add ( new BasicNameValuePair ( authInfo . getPasswordFormStr ( ) , authInfo . getPassword ( ) ) ) ; try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity ( formParams , "UTF-8" ) ; httpPost . setEntity ( entity ) ; httpClient . execute ( httpPost ) ; logger . debug ( "Successfully Logged in with user: " + authInfo . getUsername ( ) + " to: " + authInfo . getHost ( ) ) ; } catch ( UnsupportedEncodingException e ) { logger . error ( "Encountered a non supported encoding while trying to login to: " + authInfo . getHost ( ) , e ) ; } catch ( ClientProtocolException e ) { logger . error ( "While trying to login to: " + authInfo . getHost ( ) + " - Client protocol not supported" , e ) ; } catch ( IOException e ) { logger . error ( "While trying to login to: " + authInfo . getHost ( ) + " - Error making request" , e ) ; } }
form authentication < br / > official example : https : / / hc . apache . org / httpcomponents - client - ga / httpclient / examples / org / apache / http / examples / client / clientformlogin . java
