2012-09-27 40 views
0

我試圖做一個Android的多部分POST,使用下面的代碼我需要做什麼外部JARS來完成Android Multipart POST?

DefaultHttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost(urlString); 

     File file = new File(pic); 

     Log.d(TAG, "UPLOAD: setting up multipart entity"); 

     MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
     Log.d(TAG, "UPLOAD: file length = " + file.length()); 
     Log.d(TAG, "UPLOAD: file exist = " + file.exists()); 

     try { 
      mpEntity.addPart("datafile", new FileBody(file, "application/octet")); 
      mpEntity.addPart("id", new StringBody("1")); 
     } catch (UnsupportedEncodingException e1) { 
      Log.d(TAG, "UPLOAD: UnsupportedEncodingException"); 
      e1.printStackTrace(); 
     } 

     httppost.setEntity(mpEntity); 
     Log.d(TAG, "UPLOAD: executing request: " + httppost.getRequestLine()); 
     Log.d(TAG, "UPLOAD: request: " + httppost.getEntity().getContentType().toString()); 


     HttpResponse response; 
     try { 
      Log.d(TAG, "UPLOAD: about to execute"); 
      response = httpclient.execute(httppost); 
      Log.d(TAG, "UPLOAD: executed"); 
      HttpEntity resEntity = response.getEntity(); 
      Log.d(TAG, "UPLOAD: respose code: " + response.getStatusLine().toString()); 
      if (resEntity != null) { 
       Log.d(TAG, "UPLOAD: " + EntityUtils.toString(resEntity)); 
      } 
      if (resEntity != null) { 
       resEntity.consumeContent(); 
      } 
     } catch (ClientProtocolException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

這崩潰與 「java.lang.noclassdeffounderror org.apache.http.entity.mime.multipartentity」 在

MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

我的猜測是這是與我使用的外部罐子。我的項目中有一個Libs文件夾,並且在我的項目構建路徑中引用了以下文件。

HttpClient的-4.2.jar,的HttpCore-4.2.jar和httpmime-4.2.jar

這些是正確的版本?或者我需要更多的JARS?

回答

相關問題