Using curl to post data from a file
The Content-Type entity in the header specifies the type of media of the resource we are sending. You can use this to read the values from a JSON file or send it as raw. Suppose you want to make requests in the command-line using cURL, but you have the data to send stored in a file. You can use the Content-Type to specify the media type and then pass the file path containing the data.
To send this data from a JSON file, we can use the -d and then pass the filename as shown in the command below:. In this tutorial, we have discussed how to make POST requests and pass data in various formats. It is good to keep in mind that besides being very powerful, cURL is also very flexible. Anywho, this is what finally did the trick for me:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Asked 8 years, 9 months ago. Active 2 months ago. Viewed k times. Roy Hinkley. Roy Hinkley Roy Hinkley 8, 18 18 gold badges 71 71 silver badges bronze badges. Add a comment. Active Oldest Votes. I believe you're looking for the filename syntax, e. Jeffrey Froman Jeffrey Froman 5, 1 1 gold badge 14 14 silver badges 10 10 bronze badges. Use double escapes to delimit data we wan to post.
What if we have more data that is not suitable to write one by one of specifying from command line. Or we may need to provide data as a file. We can use the same --data option but we have to provide the file name with prefix. In this example, we will provide a file named mydata. Up to now, we have used the default Content-type.
0コメント