I get the error curl: Can't open 'files=#1.txt'! when trying to run code:
curl -v -XPOST -k -H "Accept: application/json" -T "files=#1.txt" https://192.168.1.102/
any suggestion on how to pass the text file's name properly?
-T is for PUT and wants a file name only:
curl -T 1.txt https://192.168.1.102/
You seem to want to POST a file? If you want it sent "plainly", you probably want:
curl -H "Accept: application/json" --data-binary #1.txt https://192.168.1.102/
If you want to instead send the file as a multipart formpost, you might do it similar to:
curl -F files=#1.txt https://192.168.1.102/
Related
I have the problem, that curl doesn't upload all my data, when uploading with -d #-
The following command doesn't work:
tar -cz folder | curl -X PUT -d #- http://example.com/api/take/file
The following command works:
tar -cz folder | curl -X PUT -T - http://example.com/api/take/file
Does somebody know what is the reason for this behaviour.
Ok I found the root cause in the docs of curl:
--data-ascii <data>
(HTTP) This is just an alias for -d, --data.
So when you use just -d then the data will sent as ascii.
According to the docs binary data should be sent with --data-binary and indeed the following command works
tar -cz folder | curl -X PUT --data-binary #- http://example.com/api/take/file
There is a sample in Jira API doc:
curl -D- -X GET -H "Authorization: Basic ZnJlZDpmcmVk" -H "Content-Type: application/json" "http://kelpie9:8081/rest/api/2/issue/QA-31"
What exactly does the -D- parameter mean? There is no description in curl documentation.
I'm also not sure whether -D- and -D mean the same thing.
It dumps headers to stdout.
The -D flag dumps headers to a file, and the following - instructs it to dump to stdout. From the linked spec:
-D, --dump-header
Write the protocol headers to the specified file.
It doesn't specify for this option, but this works like other options that take a filename:
Use "-" as filename to have the output sent to stdout.
Need an help in doing grep of 3 variables from the curl commands console output.
By executing the below curl command i get some output which prints in the console itself. I need to grep some variables(say staus, name, url) and redirect it to a file.
curl -v -X POST -D tmp.txt -H "Content-Type:text/plain" --data "$SECRET" -H "Accept:application/xml" -H "Connection:close" http://google.com/api/search
Some of your responses must be going to stderr, try:
curl ... | grep 'pattern' &> filename
I'd recommending using slightly different options to curl if you want to process the output. If I were looking for the Expires header:
curl -si -X POST -H "Content-Type:text/plain" --data "$SECRET" -H "Accept:application/xml" -H "Connection:close" http://google.com/api/search
If you want the HTTP status, you can just do this:
curl -si -X POST -H "Content-Type:text/plain" --data "$SECRET" -H "Accept:application/xml" -H "Connection:close" http://google.com/api/search | head -1
That'll print HTTP/1.1 301 Moved Permanently -- add an |awk '{print $2}' to the end of that and you'll get only the numeric status.
I am using the url at the developer-api.nest.com site, and my request is re-directed to the firebase-apiserver01...01.dapi.production.nest.com
I get the correct structured data back, using this dos command:
curl -v -k -L -X GET "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE"
I get the error 'Invalid content sent' when I send this PATCH
curl -v -k -L -X PATCH "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE" -H "Content-Type: application/json" -d '{"away":"home"}'
I have tried adding '.json' before the question mark, but get the same error.
To set the structure to home/away you'll need to send a PUT request for example as follows:
curl -v -L -X PUT "https://developer-api.nest.com/structures/g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '{"away":"home"}'
Hope that helps
--Nagesh
I am trying to update an object using curl.
There are 2 approaches I am trying:
1] Provide usr/pswd in patch reques
=> says "Warning: You can only select one HTTP request!"
2] Save login cookie first and use it to perform patch
with -I => says "Warning: You can only select one HTTP request!"
without -I => [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
Here are the requests:
1] Provide usr/pswd in patch request
curl -I -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url?un=<uname>&pw=<pwd>/<path to obj>/<key>' --trace-ascii trace.OUT
Warning: You can only select one HTTP request!
2] Save login cookie first and use it to perform patch
curl -c cookies.txt 'https://url?un=<uname>&pw=<pwd>'
curl -b cookies.txt -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url/<path to obj>/<key>'
=>[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
curl **-I** cookies.txt -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url/<path to obj>/<key>'
=> Warning: You can only select one HTTP request!
We have a tool that can perform the patch using a UI and I checked the request/headers in firebug and seems like I have everything in the request. However I want to script this call.
Any suggestions?
Thanks!
"-I" implies a HEAD request, but you specify a HTTP method of "PATCH". Curl complains that it can't do both at the same time.