在多部分POST中是否可以有嵌套的MultipartEntities或FormBodyPart? [英] Is it possible to have a nested MultipartEntities or FormBodyPart in a multipart POST?

查看:75
本文介绍了在多部分POST中是否可以有嵌套的MultipartEntities或FormBodyPart?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MultipartEntity在以下服务器POST请求中进行一些操作:

I'm trying to make something the following server POST request using MultipartEntity:

parameters: {"parameter1"=>"parameter1", "parameter2"=>{"sub_parameter1"=>"sub_parameter1", "sub_parameter2"=>"sub_parameter2"}}

我目前正在使用类似的东西:

I am currently using something like:

multipartEntity.addPart("parameter1", new StringBody("parameter1"));

FormBodyPart parameter2 = new FormBodyPart("parameter2", new StringBody("")); // It wouldn't allow a null ContentBody

parameter2.addField("sub_parameter1", "sub_parameter1");
parameter2.addField("sub_parameter2", "sub_parameter2");

但是,子字段不携带.我得到:

However, the sub fields do not carry though. I just get:

parameters: {"parameter1"=>"parameter1", "parameter2"=>""}

如何在其中包含的MultipartEntity或FormBodyPart元素中创建嵌套结构?

How do I create a nested structure in either the MultipartEntity or the FormBodyPart elements it contains?

推荐答案

一旦您了解了表单条目是如何通过HTTP连接传输的,您将了解到,多形式请求以及嵌套在嵌套形式中的任何内容都是不可能的网址编码的请求.

once you've seen how the form entries are transferred over HTTP connection, you'll understand it's impossible to have anything nested with the multiform request as well as with the url-encoded request.

事情很简单.多部分表单请求的格式为:

things are very simple. multipart form request has the format of:

--- content-boundary ---
Content-Disposition: form-data; name="form_data_name"

[content (skipped)]
--- content-boundary ---

就是这样.有以下格式的单个数据表单条目流:[表单条目名称]-> [表单条目内容],该表单对表单中的每个条目重复.它不是递归的,因此可能没有任何嵌套结构.

that's it. there's stream of single data form entries in the format: [form entry name] -> [form entry content] that repeats for every entry in the form. it's not recursive, therefore there may not be any nested structures.

来源:

  1. 17.13.4表单内容类型
  2. RFC 2045 Internet消息正文

这篇关于在多部分POST中是否可以有嵌套的MultipartEntities或FormBodyPart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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