带有 Content-Disposition 的 HttpClient 帖子 [英] HttpClient post with Content-Disposition

查看:32
本文介绍了带有 Content-Disposition 的 HttpClient 帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好.

通常我正在处理这样的发布请求name1=value1&name2=value2,我的代码是

Usually I'm working with post request like thatname1=value1&name2=value2 and my code is

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name1", "value1"));
httppost.setEntity(new UrlEncodedFormEntity("name2","value2");

但现在我有这样的帖子

-----------------------------17911109517875 Content-Disposition: form-data;
name="PERSON*1[F*2][2664]" value1 
-----------------------------17911109517875 Content-Disposition: form-data; 
name="PERSON*1[I*3][2776]" value2 
-----------------------------17911109517875 Content-Disposition: form-data;  
name="PERSON*1[O*4][2778]" value3

所以,据我所知,我应该这样做

So, as far as I know, I should do

nameValuePairs.add(new BasicNameValuePair("PERSON*1[F*2][2664]", "value1"));

但是 content-disposition 呢?

But what with content-disposition ?

谢谢.

推荐答案

您需要利用 HttpClient 的 HttpMime 支持.这不是 Android 自带的,因此您必须将其与您的应用程序捆绑在一起.

You'll need to utilize HttpClient's HttpMime support. This is not included out of the box with Android so you will have to bundle it with your application.

一个例子,根据你的帖子可以完成如下:

An example, based on your post could be accomplished as follows:

    MultipartEntity mpe= new MultipartEntity();
    FormBodyPart part1= new FormBodyPart("PERSON*1[F*2][2664]", new StringBody("value1"));
    FormBodyPart part2= new FormBodyPart("PERSON*1[I*3][2776]", new StringBody("value2")); 
    FormBodyPart part3= new FormBodyPart("PERSON*1[O*4][2778]", new StringBody("value3"));
    mpe.addPart(part1);
    mpe.addPart(part2);
    mpe.addPart(part3);

以上输出到流的示例如下:

An example of the above output to a stream would be as follows:

--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A
Content-Disposition: form-data; name="PERSON*1[F*2][2664]"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

value1
--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A
Content-Disposition: form-data; name="PERSON*1[I*3][2776]"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

value2
--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A
Content-Disposition: form-data; name="PERSON*1[O*4][2778]"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

value3
--ZV5t1WLAh04TJTqjyBJBSDL3M69xu0A--

我相信该库或多或少是独立的,可以从 httpclient 网站检索.

I believe the library is more or less stand-alone and can be retrieved from the httpclient website.

这篇关于带有 Content-Disposition 的 HttpClient 帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆