POST csv/Text file using cURL

无人久伴 提交于 2019-12-23 08:54:13

问题


How can I send POST request with a csv or a text file to the server running on a localhost using cURL.

I have tried curl -X POST -d @file.csv http://localhost:5000/upload but I get

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

My server is flask_restful API. Thanks a lot in advance.


回答1:


There are many alternate ways to accomplish this. One way is I have used the following:

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

Eg. curl -F data=@data.csv localhost:5000/h

Your command can also be changed slightly like this

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

The above is one of the many ways.It can be sent either as a part of form or data, or multipart, etc. You can refer Medium Post




回答2:


Curl's default Content-Type is application/x-www-form-urlencoded so your problem is probably that the data you are POSTing is not actually form data. It might work if you set the content type header properly:

-H "Content-Type: text/csv"

Though it does depend on the server.



来源:https://stackoverflow.com/questions/50998620/post-csv-text-file-using-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!