curl -b -j "Content-Type: application/json" -d '["quer
y:"{"MATCH n RETURN n"}]' http://localhost:7474/db/data/
curl: (6) Could not resolve host: Content-Type
Hello,
i want get JSON from. With curl and write it to a local file.
So i can do other things with it.
But when executing this command i get could not resolve Content-Type.
i've tried:
curl -b -j Content-Type: application/json' without the double quotation mark ("")
but then i get this as result
curl: (6) Could not resolve host: Content-Type
curl: (6) Could not resolve host: application
Now i've fixed this syntax error
curl -b -j -d '["query:"{"MATCH n RETURN n"}]' http://
localhost:7474/db/data/ -o .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 28 0 0 100 28 0 13 0:00:02 0:00:02 --:--:-- 13
But no data:(
I had success with:
curl -b -j -H "Content-Type: application/json" -d '{"query":"match n return n limit 10"}}' http://localhost:7474/db/data/cypher
Related
This question already has answers here:
When to wrap quotes around a shell variable?
(5 answers)
Closed 3 years ago.
I want to POST a json in bash script using curl but i am getting error that is dependent on the content..
I am getting error
Rebuilt URL to: "major":"1221",/
Illegal port number
Closing connection -1
curl: (3) Illegal port number
Note: Unnecessary use of -X or --request, POST is already inferred.
Rebuilt URL to: "minor":"32112",/
Illegal port number
Closing connection -1
curl: (3) Illegal port number
curl: (3) [globbing] unmatched close brace/bracket in column 48
This works
#!/bin/bash
param='[{"timestamp":"value","sourceId":"fe28edab963de6788"}]'
echo $param
curl -d $param -H "Content-Type: application/json" -H "X-Security-AuthKey: 84C0712F-856D-4EC7-B136-FA39B5FFE995" -H "Type: DATA" -H "Device: RaspberryPI" -X POST "https://test.api.com/webhook" -v
but this does not work...
#!/bin/bash
param='[{"timestamp":"1554895106","sourceId":"fe28edab963de6788","uuid":"F7826DA6-4FA2-4E98-8024-BC5B71E0893E", "major":"1221", "minor":"32112", "rssi":"-63","distance":".26307557616382837295"}]'
echo $param
curl -d $param -H "Content-Type: application/json" -H "X-Security-AuthKey: 84C0712F-856D-4EC7-B136-FA39B5FFE995" -H "Type: DATA" -H "Device: RaspberryPI" -X POST "https://test.api.com/webhook" -v
Like #Aaron said, the shell is splitting up your value because it has spaces in it. By default, Bash splits "words" by spaces, tabs, and newlines. "weak quotes" (double quotes) will escape this word-splitting process while still allowing you to expand variables.
curl -d "$param" ...
Trying to upload some measurements to COSMOS. I have an COSMOS account.
Also, I'm using the tutorial here: https://github.com/ging/fiware-cosmos/blob/master/doc/manuals/quick_start_guide_new.md
I'm stuck on Step 3: Upload some data to HDFS.
This is the process flow for me:
curl -v -X PUT -T measurements.txt "http://storage.dit.upm.es:14000/webhdfs/v1/user/MY-USERNAME/MY-FOLDER/measurements.txt?op=CREATE&user.name=MY-USERNAME" -H "Content-Type: application/octet-stream" -H "X-Auth-token: MY-ACCESS-TOKEN"
After this request, I get the expected response according to the tutorial. But then on the next request...
curl -v -X PUT -T measurements.txt "http://dev-fiwr-svc-01.tid.es:14000/webhdfs/v1/user/MY-USERNAME/MY-FOLDER/measurements.txt?op=CREATE&user.name=MY-USERNAME&data=true" -H "Content-Type: application/octet-stream" -H "X-Auth-token: MY-ACCESS-TOKEN"
...I get the following response:
* Hostname was NOT found in DNS cache
* Could not resolve host: dev-fiwr-svc-01.tid.es
* Closing connection 0
curl: (6) Could not resolve host: dev-fiwr-svc-01.tid.es
Anybody else that has had the same problem?
Thanks to #Shihe Zhang for the idea!
Changed dev-fiwr-svc-01.tid.es:14000 to storage.dit.upm.es:14000 and my file was uploaded.
I'm using cURL to connect to a remote host. Some of my commands execute just fine (like authentication via POST and pulling information via GET). I'm getting a weird error when trying to use a POST to add information with regards to content length. This is my syntax;
curl -k -i -b sessionid -X POST https://hostname/BeyondTrust/api/public/v3/Workgroups/apiTest/Assets?AssetName=string&DnsName=string&DomainName=string -H "Content-Type: application/json" -H "Authorization: PS-Auth key=b8e1...2c27; runas=userName; pwd=[password]" -d ""
This is my output;
[1] 58164
[2] 58165
-bash: -H: command not found
[2]+ Done DnsName=string
HTTP/1.1 411 Length Required
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 27 Oct 2017 14:29:12 GMT
Connection: close
Content-Length: 344
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>
I've researched it, and this is a common problem, apparently. -d "" does not fix and have tried --ignore-content-length and Content-Length: 0 in the headers, but I still have the same issue. Can someone point me in the right direction?
You need to quote the URL because it contains some special shell characters.
This output tells you something went wrong:
[1] 58164
[2] 58165
-bash: -H: command not found
[2]+ Done DnsName=string
Your command got split into multiple jobs and resulted in some errors because of the & in the URL's query string.
Putting the URL in double-quotes " will fix the issue.
curl -k -i -b sessionid \
-X POST \
"https://hostname/BeyondTrust/api/public/v3/Workgroups/apiTest/Assets?AssetName=string&DnsName=string&DomainName=string"
This way your URL will be interpreted properly and the shell won't try to start it in the background.
so i have this curl request (running on a windows cmd prompt):
curl --insecure -g -X POST -H "Content-Type: application/json" -d {\"from\":\"someName\",\"message\":\"this is a message\"} https://some/website/here
When i run this, i get an error:
curl: (6) Could not resolve host: is; Host not found
curl: (6) Could not resolve host: a; Host not found
curl: (6) Could not resolve host: message; Host not found
Which seems to be because the json is munged up - the spaces are not working!
How would i send this message, if i wanted spaces to be in the, uh, message?
Use double quotes " and use %20 in url
Just tried on my windows command prompt now. You were missing escape on the DATA part
Your code
curl --insecure -g -X POST -H "Content-Type: application/json" -d {\"from\":\"someName\",\"message\":\"this is a message\"} https://some/website/here
should be escaped like this
curl --insecure -g -X POST -H "Content-Type: application/json" -d "{\"from\":\"someName\",\"message\":\"this is a message\"}" https://some/website/here
You just need to quote your JSON as a string literal:
curl --insecure -g -X POST -H "Content-Type: application/json" -d "{\"from\":\"someName\",\"message\":\"this is a message\"}" https://some/website/here
also, use the -V for more info on what is happening (it threw this error "parse error near `}'").
try this (instead of -d ), e.g.:
--data-raw "{"blah":"a string with spaces"}"
Just wondering how I can send a curl command with the -d option specifying a file with its path and not a file in the current directory.
This is what I'm getting when I try to test my app with the json file in the local dir. Both the app and myself are happy:
curl -XPOST -H 'Content-Type:application/json' -d #all_fields.json http://testcomp.lab.net:8080/stats -v -s
* About to connect() to testcomp.lab.net port 8080
* Trying 10.93.2.197... connected
* Connected to testcomp.lab.net (10.93.2.197) port 8080
> POST /stats HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: testcomp.lab.net:8080
> Accept: */*
> Content-Type:application/json
> Content-Length: 2882
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 200 OK
< Content-Length: 0
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
This is what I'm getting when I specify a json file that's in another directory
curl -XPOST -H 'Content-Type:application/json' -d #json/all_fields.json http://testcomp.lab.net:8080/stats -v -s
"Invalid json for Java type interface java.util.List"
Warning: Couldn't read data from file "json/all_fields.json", this makes an
Warning: empty POST.
<snip snip>
<snip snip>
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Transfer-Encoding: chunked
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
I didn't see anything in the man page for curl for specifying directories for files passed in as data. Am I unfortunately limited to files in the local directory or is there a special way to specify files in different directories? Thanks in advance for your help.
The -d # command option accepts any resolvable file path, as long as the path actually exists. So you could use:
a path relative to the current directory
a fully qualified path
a path with soft-links in it
and so on
To wit, just the same as hundreds of other *Nix style commands. One quick note, the -d option will attempt to url encode your data, which from what you describe isn't actually what you want. You should use the --data-binary option instead. Something like this:
curl -XPOST
-H 'Content-Type:application/json'
-H 'Accept: application/json'
--data-binary #/full/path/to/test.json
http://localhost:8080/easy/eservices/echo -v -s