我有一個終點,我可以這樣上傳文本文件,且捲曲:用的multipart/form-data的使用CLJ-AJAX HTTP POST請求
curl -X POST -H "Content-Type: multipart/form-data" -F "[email protected]/resources/speciesDiffusion.tree" http://localhost:4000/continuous/tree
現在我需要從瀏覽器中發送了類似的請求但
(ajax/ajax-request
{:uri (str "http://localhost:4000" "/continuous/tree")
:method :post
:params {:treefile file}
:handler #(println %1)
:format (ajax/text-request-format)
:response-format (ajax/json-response-format {:keywords? true})})
給了我一個(JSON很好的轉化,所以我得到的那部分去,這是很好的)錯誤響應:
[false {:status 500, :status-text , :failure :error, :response {:timestamp 1494279686227, :status 500, :error Internal Server Error, :exception org.springframework.web.multipart.MultipartException, :message Current request is not a multipart request, :path /continuous/tree}}]
一另外,在瀏覽器中,我可以看到內容類型標題沒有正確設置,但是我無法使用其他格式和:params的其他組合。
謝謝,但我很清楚現有的文檔,但不幸解決不了問題。 – fbielejec
我建議再讀一遍,因爲你的例子沒有指定':body'或任何':headers' – acron
根據官方文檔::params - 與請求一起發送的參數,格式相關的::transit和: edn可以發送任何東西,:json和:raw需要給出一張地圖。 GET會將參數添加到查詢字符串中,POST會將參數放入正文中。 – fbielejec