POST csv/Text 文件使用 cURL

POST csv/Text file using cURL

如何使用 cURLlocalhost 上将带有 csv 或文本文件的 POST 请求发送到服务器 运行。

我试过 curl -X POST -d @file.csv http://localhost:5000/upload 但我得到了

{ "message": "The browser (or proxy) sent a request that this server could not understand." }

我的服务器是flask_restful API。提前致谢。

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

-H "Content-Type: text/csv"

虽然它确实取决于服务器。

有许多替代方法可以实现此目的。一种方法是 我使用了以下内容:

curl -F ‘data=@<file_location>’ <URL>

例如。 curl -F data=@data.csv localhost:5000/h

你的命令也可以像这样稍微改变一下

curl -X POST -H 'Content-Type: text/csv' -d @file.csv http://localhost:5000/upload

以上是众多ways.It可以作为表单或数据的一部分,或多部分等发送。您可以参考Medium Post