将邮递员请求转换为 cURL

时间:2020-12-30 04:47:53

标签: curl postman

我正在尝试将 Postman 请求转换为 cURL 格式,但效果不佳。 我想发送一个包含表单数据的请求,其中包含 csv 文件(内容类型 url 表单编码)。当我尝试使用 Postman 时它有效,但当我尝试通过 Postman 使用转换后的 cURL 代码时无效。

我附上了我的邮递员设置和通过邮递员转换的 cURL 代码。 我是否必须处理一些事情才能使用 cURL 发送文件?

(也欢迎英文更正!) enter image description here enter image description here

2 个答案:

答案 0 :(得分:1)

Curl 的默认 Content-Type 是 application/x-www-form-urlencoded 所以你的问题可能是你发布的数据实际上不是表单数据。如果您正确设置内容类型标题,它可能会起作用:

<块引用>

curl -X POST "your_url" -H "Content-Type: text/csv" -F "csvfile=@sample.csv"

答案 1 :(得分:1)

清除并留下成功案例。
谢谢你的回答!而且我也提到了下面的页面!

use curl to POST multipart/form-data, file and lots of key-value pairs

curl -v -X POST 'somewhere' \
--form 'key="value"' \
--form csvfile=@"filePath/sample.csv;type=text/csv"

curl -v -X POST 'somewhere' \
--form 'key=value' \
--form csvfile=@"filePath/sample.csv;type=multipart/form-data"