Linux CURL如何同时POST文件和数据url编码?

时间:2018-02-09 16:36:36

标签: linux bash curl urlencode

我发送带有文本文件和一些key = value的POST请求时遇到问题(值包含特殊字符,需要进行编码,例如:query = select c + a%b)。

我尝试过这样做,它会返回错误Warning: You can only select one HTTP request!

curl -F "file=@path_to_text_file" 
--data-urlencode "query=select c + a % b" "http://localhost:8082/app"

删除--data-urlencode然后它可以运行,但查询的值不会被编码。

我更喜欢不需要手动编码查询。

1 个答案:

答案 0 :(得分:1)

这将进行上传,然后发送帖子请求

curl -F "file=@path_to_text_file" "http://localhost:8082/app" --next --data-urlencode "query=select c + a % b" "http://localhost:8082/app"