close
public static void Update() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(
    CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    
    HttpPost httppost = new HttpPost("http://mpss.csce.uark.edu/~tsumar/test/upload_file.php");
    File file = new File("image.jpg");
    
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file, "image/jpeg");
    mpEntity.addPart("file", cbFile);
    
    httppost.setEntity(mpEntity);
    System.out.println("executing request " + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    
    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        System.out.println(EntityUtils.toString(resEntity));
    }
    if (resEntity != null) {
        resEntity.consumeContent();
    }
    
    httpclient.getConnectionManager().shutdown();
}
 
   
arrow
arrow
    文章標籤
    Java
    全站熱搜

    techdrew 發表在 痞客邦 留言(0) 人氣()