title: convert curl request into HttpURLConnection
body: <p>I am trying to implement a client that logins first and do some staff. 
  This is my curl request:</p>
  
  <pre><code>curl -v https://api.example.com/api-token-auth/ \
     -H "Accept: application/json" \
     -d "username=myusername&amp;password=mypassword"
  </code></pre>
  
  <p>I want to convert it into java code. Here is what I have tried:</p>
  
  <pre><code>HttpURLConnection conn;
  URL obj = new URL("https://api.example.com/api-token-auth/");
  URL obj = new URL(quoteURL);
  conn = (HttpURLConnection) obj.openConnection();
  conn.setRequestMethod("POST");
  conn.setDoOutput(true);
  String userpass = "username=myusername" + "&amp;" + "password=mypassword";
  String basicAuth =  new String(Base64.getEncoder().encode(userpass.getBytes()));
  conn.setRequestProperty("Authorization", basicAuth);
  conn.setRequestProperty( "Accept", "*/*" );
  conn.setRequestProperty( "Accept-Encoding", "gzip, deflate" );
  conn.setRequestProperty( "Accept-Language", "en;q=1, fr;q=0.9, de;q=0.8,ja;q=0.7, nl;q=0.6, it;q=0.5" );
  conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded; charset=utf-8" );
  conn.setRequestProperty( "API-Version", "1.3.0" );
  conn.setRequestProperty("Connection", "keep-alive");
  conn.setRequestProperty( "Accept", "*/*" );
  conn.setRequestProperty("User-Agent", "Mozilla/5.0");
  conn.connect();
  InputStreamReader inputStreamReader = new InputStreamReader(conn.getInputStream());
  BufferedReader in = new BufferedReader(inputStreamReader);
  String inputLine;
  StringBuffer response = new StringBuffer();
  
  while ((inputLine = in.readLine()) != null) {
  response.append(inputLine);
  }
  in.close();
  conn.disconnect();
  return response;
  </code></pre>
  
  <p>Then I receive this error:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.example.com/api-token-auth/
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
  </code></pre>
  
  <p>I have tried several possible solutions, but no luck. I could nit find what I am doing wrong. </p>