Java 如何将带有一些数据的mp3从android上传到服务器?

Java 如何将带有一些数据的mp3从android上传到服务器?,java,android,Java,Android,我想从android上传一个mp3文件和一些数据到服务器。在这里,我需要发送一些参数与mp3文件在同一时间。我找了很多,但是没有得到正确的结果。如果有人有任何想法,请与我分享。我确实是 提前感谢。使用此代码与其他参数一起上载 private void uploadVideo(String audioPath,String param1,String param2) throws ParseException, IOException { HttpClient h

我想从android上传一个mp3文件和一些数据到服务器。在这里,我需要发送一些参数与mp3文件在同一时间。我找了很多,但是没有得到正确的结果。如果有人有任何想法,请与我分享。我确实是


提前感谢。

使用此代码与其他参数一起上载

private void uploadVideo(String audioPath,String param1,String param2) throws ParseException, IOException {

                HttpClient httpclient = new DefaultHttpClient();

                //post request to send the video 
                HttpPost httppost = new HttpPost("your url of server");
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy( policy);
                FileBody audio_file1 = new FileBody(new File(audiopath));
                StringBody param1 = new StringBody("your parameter1");
                StringBody param21 = new StringBody("your parameter2");

                MultipartEntity reqEntity = new MultipartEntity();
                reqEntity.addPart("argument that your server take", audio_file1);
                reqEntity.addPart("argument that your server take", param1);
                reqEntity.addPart("argument that your server take", param2);

                httppost.setEntity(reqEntity);

                // DEBUG
                System.out.println( "executing request " + httppost.getRequestLine( ) );
                HttpResponse response = httpclient.execute( httppost );
                HttpEntity resEntity = response.getEntity( );

                // DEBUG
                System.out.println( response.getStatusLine( ) );
                if (resEntity != null) {
                  System.out.println( EntityUtils.toString( resEntity ) );
                } // end if
                if (resEntity != null) {
                  resEntity.consumeContent( );
                } // end if

                httpclient.getConnectionManager( ).shutdown( );
            } 

在异步任务中使用以下代码:

File yourfile= new File(your path on sdcard);
 HttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(YOUR URL);

MultipartEntity entity = new MultipartEntity();
entity.addPart("FileName",new StringBody(yourfile));
entity.addPart("FileDescription",new StringBody(yourfileName));

httpost.setEntity(entity);

HttpResponse response = httpclient.execute(httpost);

一个简单的谷歌搜索展示了很多实现这一点的想法。你试过哪些?