带有 Map 的 Rest POST API 的 Curl 命令<String, Object>

问题描述 投票:0回答:1

如果我们需要使用Map作为curl命令中的请求参数来调用REST API,如何传递Map,我尝试过:

@PostMapping("/abc/aa/{type}")
    private final ResponseEntity<Void> invoke(@PathVariable String type,
            @RequestParam(name = "params", required = false) Map<String, Object> params)
    {
    }

Curl 命令如下:

curl -G -X POST --url http://localhost:8585/abc/aa/default_aa.TEST_varchar100_94946640?params='apiTriggered=true;fromPk=7898989898'

但它抛出错误:

{"success":false,"header":null,"data":null,"messageKey":"error.500","message":"error.500","errors":[],"exceptions":[{"messageData":{},"resource":"Throwable","messageKey":"Throwable","message":"Internal exception was caught and handled by CustomErrorController (see logs for the trace); UID: ad4e6165-7eed-4682-b587-bca6a6b2532e; message: org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map': no matching editors or conversion strategy found","stackTrace"
any samples for a REST API with Map as a parameter - and curl command for the same will help me.

我尝试传递如下参数:

curl -G -X POST --url http://localhost:8585/abc/aa/default_aa.TEST_varchar100_94946640?apiTriggered=true&fromPk=7898989898

params(map) 未保存这些值,map 显示为 null。

有些人关闭了问题,在关闭之前请提及需要哪些额外信息。

java rest curl
1个回答
0
投票

CURL命令发送json

curl -X POST  -H "Content-Type: application/json" -d '{"key":"value"}'  http://localhost:8000?param1=value1&param2=value2
  • d - 传递数据
  • H - 传递标头
  • X - 用于请求
  • F - 用于表单数据

将param1和Value1替换为查询参数的key和value 替换json数据值的key&value

欲了解更多信息,请参阅 如何使用 CURL 从命令行发出 API 请求

© www.soinside.com 2019 - 2024. All rights reserved.