晚上好。
通常我用这样的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的发布与内容处置
发布评论