java - 如何使用 CURL 将多格式文件和 JSON 发布到 Springboot Restful Webservice
问题描述
我正在尝试使用 CURL 向以下端点发出 POST 请求,该端点以 html 文件和 json 字符串作为参数。
下面是第一个服务的端点签名,它创建一个 html 字符串,然后作为 json 发送到第二个微服务:
@PostMapping(path = "/pdf-template", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<String> bindTemplateData(
@ApiParam(value = "BindDataRequest payload", required = true)
@RequestParam MultipartFile template, @RequestParam String templateDataJson) throws IOException {
}
以下 curl适用于 curl 命令中嵌入的 Json:
curl --form 'template=@/Users/joe.deen/ms-template-binder/src/main/resources/html-template/Template.html' --form 'templateDataJson={"cost":"2.00","name":"James Milner 2"}' http://localhost:8081//pdf/download | base64 -D > test.pdf
但是,我想从 json 中读取,而不是直接嵌入数据,例如
curl --form 'template=@/Users/joe.deen/ms-template-binder/src/main/resources/html-template/Template.html' --form 'templateDataJson=@/Users/joe.deen/ms-template-binder/src/main/resources/json/test.json' http://localhost:8081//pdf/download | base64 -D > test.pdf
第二个 curl 命令不起作用。它在服务中抛出一个空指针。
请,我如何从我的 mac-os 机器上的 json 文件中读取并作为第二个参数传递给我的端点,而不是嵌入使 curl 命令混乱的 json 内容。数据通过 Resttemplate 客户端发送。
提前感谢您的帮助。
解决方案
在 json 文件路径末尾添加;type=application/json
如下:
curl --form 'template=@/Users/joe.deen/ms-template-binder/src/main/resources/html-template/Template.html' --form 'templateDataJson=@/Users/joe.deen/ms-template-binder/src/main/resources/json/test.json;type=application/json' http://localhost:8081//pdf/download | base64 -D > test.pdf
推荐阅读
- javascript - 进行 DomSanitizer API 调用时不使用基本属性?
- javascript - 为什么js认为我的数组在某些环境中不是数组?
- python - 在python中将谷歌数据存储查询结果转换为熊猫数据框
- ios - 如何使用 Combine 将 NSManagedObject 绑定到表/集合视图单元格?
- windows - 如何在 DevTest Lab 中创建 windows x86 VM?
- windows - 如何确保 QFrame 标题使用 Window 10 的“使文本变大”缩放自动缩放?
- azure - 将逻辑应用部署到 Azure 并注册到 Active Directory Azure
- wordpress - 如何在视频中添加自动切换
- kubernetes - GKE LoadBalancer 静态 IP
- c# - 用于公共语言运行时 Visual Studio 2017 的内联汇编程序