簡體   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