我尝试在控制器中处理HttpPost请求。
[HttpPost]
[Route("device/configuration/config")]
public ActionResult<string> config([FromForm, Required] string class, [FromForm, Required] int account_id, [FromForm] string[] config, [FromForm] string creator_name)
如您所见,我想获取配置数组。 在我的测试中,我请求此端点,并以“ config:“ config1”“,” config:“ config2”“的形式传递数组。而且一切正常。但是当我大张旗鼓地调用它时,我得到的不是配置数组,而是一个包含一项的数组,其中所有配置都用逗号分隔。
昂首阔步
curl -X POST "localhost:7980/device/configuration/account_config" -H "accept: text/plain" -H "Content-Type: multipart/form-data" -F "device_class=someClass" -F "account_id=2" -F "config="123","321","222"" -F "creator_name=someCreator"
答案 0 :(得分:1)
您可以这样尝试吗?
curl -X POST "localhost:7980/device/configuration/account_config" -H "accept: text/plain" -H "Content-Type: multipart/form-data" -F "device_class=someClass" -F "account_id=2" -F "config=123" -F "config=321" -F "config=222" -F "creator_name=someCreator"
问题是您必须发送3次数组参数。
您也可以这样发送:
curl -X POST "localhost:7980/device/configuration/account_config?device_class=someClass&config=123&config=321&config=222&creator_name=someCreator" -H "accept: text/plain" -H "Content-Type: multipart/form-data"