使用 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

最新更新