带有 Content

编程入门 行业动态 更新时间:2024-10-28 13:21:51
本文介绍了带有 Content-Disposition 的 HttpClient 帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

晚上好.

通常我正在处理这样的发布请求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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 14:30:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/963788.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!