title: Login in web page with cookies in Java
body: <p>I want to download a file from a web page which needs user and pass, but first I have to get the cookies. What I want to do is exactly described in this Python script, but I want to do it using Java.</p>
  
  <p>I have been reading about that, and I have found httpclient library. Is httpclient all I need? Any equivalent library for mechanize and urllib2 in java?</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>#!/usr/bin/python
  
  import mechanize, urllib2
  from urllib import urlopen, urlencode 
  
  user = 'username'
  password = 'password'
  output_file = 'name.pdf'
  
  web = "https://..."
  bills_page = "https://.../bills"
  login_web = "https://.../login/"
  file = "https://.../file_I_want"
  
  br = mechanize.Browser()
  br.open(web)
  
  data = {
      'user_username': user,
      'user_password': password,
      'idClientehidden': '',
      'answer': ''
  }
  
  response1 = urllib2.Request(login_web, urlencode(data))
  
  br.open(response1)
  br.open(bills_page)
  html_bills = br.response().read()
  
  br.open(file)
  pdf_bill = open(output_file, 'w')
  pdf_bill.write(br.response().read())
  pdf_bill.close()
  </code></pre>