title: Post a file (and more values) into a http request in java
body: <p>This is my code for making a HTTP post to an url</p>
  
  <pre><code>public static String post(String url, List&lt;BasicNameValuePair&gt; postvalues) {
      try {
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost(url);
  
          if ( (postvalues==null) ){
              postvalues= new ArrayList&lt;BasicNameValuePair&gt;();
          } 
          httppost.setEntity(new UrlEncodedFormEntity(postvalues, "UTF-8"));
  
          // Execute HTTP Post Request
          HttpResponse response = httpclient.execute(httppost);
          return requestToString(response);
      } catch (Exception e) {
          e.printStackTrace();
          return null;
      }
  
  }
  </code></pre>
  
  <p>I'd like to add also a file to the post (not a byte[] with the final, just post the file into the PHP $_FILES field. </p>
  
  <p>How can I do it? </p>
  
  <p>Thanks</p>