使用HTTP cURL将JSON数据与图像文件一起发布

我正在使用django-rest-framework,并且我有一个注册表单,它接受一些包含用户图像文件的数据。

我怎样才能用cURL来模拟这个? 我可以发布如下的JSON数据:

curl -i -X POST -H "Content-Type: application/json" -d '{"email_address":"email@address.com", "password": "Password", "display_name": "mark", "full_name": "Mark", "gender": "M", "date_of_birth": "1955-05-05", "location_id": "3"}' http://localhost/register

我如何添加一个图像字段到这个表单?


做到这一点的方法是完全删除-d选项,并用每个所需字段的-F选项替换。 这里是一个例子:

curl -i -F "email_address=email@address.com" -F "password=password" -F "display_name=mark10" -F "full_name=Mark Ten" -F "gender=M" -F "date_of_birth=1955-01-01" -F "location_id=3" -F "profile_picture=@/path/to/pic.jpg" http://localhost:1989/api/rest/v1/register
链接地址: http://www.djcxy.com/p/8585.html

上一篇: Using HTTP cURL to post JSON data with an image file

下一篇: POST JSON over CURL with basic authentication