I need to make a POST request via cURL from the command line. Data for this request is located in a file. I know that via PUT this could be done with the --upload-file option.
curl host:port/post-file -H "Content-Type: text/xml" --data "contents_of_file"
You're looking for the --data-binary argument:
curl -i -X POST host:port/post-file \
-H "Content-Type: text/xml" \
--data-binary "#path/to/file"
In the example above, -i prints out all the headers so that you can see what's going on, and -X POST makes it explicit that this is a post. Both of these can be safely omitted without changing the behaviour on the wire. The path to the file needs to be preceded by an # symbol, so curl knows to read from a file.
I need to make a POST request via Curl from the command line. Data for this request is located in a file...
All you need to do is have the --data argument start with a #:
curl -H "Content-Type: text/xml" --data "#path_of_file" host:port/post-file-path
For example, if you have the data in a file called stuff.xml then you would do something like:
curl -H "Content-Type: text/xml" --data "#stuff.xml" host:port/post-file-path
The stuff.xml filename can be replaced with a relative or full path to the file: #../xml/stuff.xml, #/var/tmp/stuff.xml, ...
If you are using form data to upload file,in which a parameter name must be specified , you can use:
curl -X POST -i -F "parametername=#filename" -F "additional_parm=param2" host:port/xxx
Most of answers are perfect here, but when I landed here for my particular problem, I have to upload binary file (XLSX spread sheet) using POST method, I see one thing missing, i.e. usually its not just file you load, you may have more form data elements, like comment to file or tags to file etc as was my case. Hence, I would like to add it here as it was my use case, so that it could help others.
curl -POST -F comment=mycomment -F file_type=XLSX -F file_data=#/your/path/to/file.XLSX http://yourhost.example.com/api/example_url
I was having a similar issue in passing the file as a param. Using -F allowed the file to be passed as form data, but the content type of the file was application/octet-stream. My endpoint was expecting text/csv.
You are able to set the MIME type of the file with the following syntax:
-F 'file=#path/to/file;type=<MIME_TYPE>
So the full cURL command would look like this for a CSV file:
curl -X POST -F 'file=#path/to/file.csv;type=text/csv' https://test.com
There is good documentation on this and other options here: https://catonmat.net/cookbooks/curl/make-post-request#post-form-data
I had to use a HTTP connection, because on HTTPS there is default file size limit.
https://techcommunity.microsoft.com/t5/IIS-Support-Blog/Solution-for-Request-Entity-Too-Large-error/ba-p/501134
curl -i -X 'POST' -F 'file=#/home/testeincremental.xlsx' 'http://example.com/upload.aspx?user=example&password=example123&type=XLSX'
I wrote a curl script to pull data from my api url into my unix terminal. But when I run the script below, I get a blank space as my output, rather than data from the api url. I don't get any standard error message, just a blank space followed by $ to enter a new command.
#!/bin/bash
INSTANCE_NAME="https://servicenow.com/ServiceNowData/tickets?ticks=4320000"
DATA_OUTPUT=$(curl -s -k -X GET -H "accept: application/json" $INSTANCE_NAME)
echo $DATA_OUTPUT
Page 404. And -H "Accept-Encoding: application/json"
I am able to execute the below cURL request (generated in PostMan) through a Git Bash in windows, and receive a response as expected.
curl -X GET \ https://test.amazon.com/production/john.stones \
-H 'authorization: Bearer dfgjdrjkdrt' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 53a3fs9a-5ce3-10fe-7f0a-33e9695ec514' \
-H 'referer: king'
I wish to run multiple cURL requests, around a thousand like the above, with the name being the value that changes in each request. I tried placing them into a batch file but each line is taken as a command, so a bit unsure as to how to structure them. Anyone know how I can run multiple cURL requests, either in sequence or parallel, in Windows 10?
I have addressed this by listing each cURL request in a batch file, replacing all single quotes with double and removed all '\' generated in Postman to divide headers. Only after this does windows run the requests successfully.
There's a public streaming Meetup API that streams JSON events: http://stream.meetup.com/2/rsvps
In a single line from the command line, I'd like to be able to redirect that stream such that each JSON object is POSTed to another API.
I've tried lots of permutations of cURL but thus far have been unable to make it work. My current attempt looks something like:
curl -s http://stream.meetup.com/2/rsvps | curl -H "Content-Type: application/json" -X POST -d #- 'http://my-api-url-here'
This produces nothing as far as I can see. The requests are not streamed to the destination API and nothing is sent to standard out. As a bonus, I'd like to see the standard output but the core requirement is streaming the JSON records to the target API.
If I try redirecting the stream to a file like:
curl -s http://stream.meetup.com/2/rsvps > output.txt
This works as expected. The challenge seems to be getting the output from the initial cURL stream to POST as data to the second.
This could work for let's say, 10 events at a time
curl -H "Content-Type: application/json" -X POST -d "[$(curl -s http://stream.meetup.com/2/rsvps | sed -n '1{p; :loop n; p; 10q; b loop}' | sed -re '1,9 s/[}]$/},/')]" 'http://my-api-url-here'
As suggested by meetup docs, the number of events may be limited using since_count and since_mtime.
I need to post a PowerPoint file to an online service which converts PPT files to PDF. I am new to Bash shell and don't know how to post PPT file from my local computer. How should I modify line below?
curl -i -H "Accept: application/pdf" -X POST http://do.convertapi.com/PowerPoint2Pdf > output
Use the --data-binary <data> option.
$ curl --data-binary #your.pdf ...