HttpClient的发布与内容处置

编程入门 行业动态 更新时间:2024-10-26 00:29:18
本文介绍了HttpClient的发布与内容处置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

晚上好。

通常我用这样的POST请求名1 =值1&放工作; 2 =值2 和我的code是

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");

但现在我有帖子这样

But now I have the post like that

-----------------------------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"));

但是,随着内容处置呢?

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.

更多推荐

HttpClient的发布与内容处置

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

发布评论

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

>www.elefans.com

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