繁体   English   中英

resttemplate等效/映射curl -T选项

[英]resttemplate equivalent/mapping of curl -T option

如果要使用Spring resttemplate,映射curl -T标志的正确方法是什么? 从-T的联机帮助页-“这会将指定的本地文件传输到远程URL”

这是一个相关的curl格式:

curl -X PUT -T /tmp/sampleFileToUpload -v 'http://testHost/URI'

这就是我所拥有的-虽然似乎没有工作

MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
map.add("file",new FileSystemResource(new File("/tmp/sampleFileToUpload")));

我已经在标题中将content-type设置为multipart / form-data,然后调用了exchange方法。 目标被写入-但不写入预期的内容-而是写入请求参数。 据我了解,curl -F选项很容易映射到-例如“ file”作为映射中的键,但是我不确定在使用resttemplate时如何映射-T。

这对我有用:

httpHeaders.add("content-type","multipart/form-data");
...
...
httpEntity = new HttpEntity<String>(fileContentsAsString, httpHeaders)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM