简体   繁体   English

HttpPost android多个实体

[英]HttpPost android multiple entities

I am trying to use MultipartEntityBuilder to set some entities in my httpPost in Android. 我正在尝试使用MultipartEntityBuilder在Android的httpPost中设置一些实体。 I downloaded httpmime-4.3.jar and I added it to Eclipse in my lib folder. 我下载了httpmime-4.3.jar并将其添加到Eclipse的lib文件夹中。 But when I execute this code: 但是当我执行以下代码时:

MultipartEntityBuilder entity = MultipartEntityBuilder.create();
entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addTextBody("PARAMS", "telo");
httpPost.setEntity(entity.build());

It produces this error: 它产生此错误:

07-30 18:21:00.172: E/AndroidRuntime(3150): FATAL EXCEPTION: AudioRecorder Thread
07-30 18:21:00.172: E/AndroidRuntime(3150): Process: com.example.telo, PID: 3150
07-30 18:21:00.172: E/AndroidRuntime(3150): java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType
07-30 18:21:00.172: E/AndroidRuntime(3150):     at org.apache.http.entity.mime.MultipartEntityBuilder.addTextBody(MultipartEntityBuilder.java:126)
07-30 18:21:00.172: E/AndroidRuntime(3150):     at org.gradiant.serverCom.SendAudioToServer.POST(SendAudioToServer.java:58)
07-30 18:21:00.172: E/AndroidRuntime(3150):     at com.example.telo.MainActivity.onFrameAcquired(MainActivity.java:133)
07-30 18:21:00.172: E/AndroidRuntime(3150):     at org.gradiant.audioAcquisition.AudioCapture.record(AudioCapture.java:113)
07-30 18:21:00.172: E/AndroidRuntime(3150):     at org.gradiant.audioAcquisition.AudioCapture.access$0(AudioCapture.java:88)
07-30 18:21:00.172: E/AndroidRuntime(3150):     at org.gradiant.audioAcquisition.AudioCapture$1.run(AudioCapture.java:79)
07-30 18:21:00.172: E/AndroidRuntime(3150):     at java.lang.Thread.run(Thread.java:841)

How can I solve this? 我该如何解决?

i think you need to set your content-type and then add it to the entity. 我认为您需要设置您的内容类型,然后将其添加到实体中。 Try something like this: 尝试这样的事情:

File f = new File(Your_file_path);

        FileBody bd = new FileBody(f);
        FormBodyPart fbp = new FormBodyPart("file", bd);
        fbp.addField("Content-Type", "audio/mp4");

         entity.addPart(fbp);

It appears that you also need this jar: 看来您也需要这个jar:

http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.3.2 http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.3.2

Please note that you may wish to consider using something like gradle or maven to manage your builds. 请注意,您可能希望考虑使用gradle或maven之类的工具来管理构建。 This way you can simply say which dependency you want and maven or gradle will automatically download load it for you and make it available on your classpath within your IDE. 这样,您可以简单地说出所需的依赖关系,并且maven或gradle会自动为您下载加载它,并使其在您的IDE中的类路径上可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM