How to pass payload via JSON file for curl?

后端 未结 1 1830
予麋鹿
予麋鹿 2020-12-04 06:12

I can successfully create a place via curl executing the following command:

$ curl -vX POST https://serve         


        
相关标签:
1条回答
  • 2020-12-04 06:43

    curl sends POST requests with the default content type of application/x-www-form-urlencoded. If you want to send a JSON request, you will have to specify the correct content type header:

    $ curl -vX POST http://server/api/v1/places.json -d @testplace.json \
    --header "Content-Type: application/json"
    

    But that will only work if the server accepts json input. The .json at the end of the url may only indicate that the output is json, it doesn't necessarily mean that it also will handle json input. The API documentation should give you a hint on whether it does or not.

    The reason you get a 401 and not some other error is probably because the server can't extract the auth_token from your request.

    0 讨论(0)
提交回复
热议问题