Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl GET request with json parameter

Tags:

json

rest

curl

People also ask

Can you pass JSON in a GET request?

To answer your question, yes you may pass JSON in the URI as part of a GET request (provided you URL-encode).

How do I send a GET request using curl?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.

How do you pass body parameters in curl command?

You can pass the body of the POST message to Curl with the -d or --data command-line option. Curl will send data to the server in the same format as the browser when submitting an HTML form. To send binary data in the body of a POST message with Curl, use the --data-binary command-line option.

What is curl in JSON?

The curl “cockpit” is yet again extended with a new command line option: --json . The 245th command line option. curl is a generic transfer tool for sending and receiving data across networks and it is completely agnostic as to what it transfers or even why.


This should work :

  curl -i -H "Accept: application/json" 'server:5050/a/c/getName{"param0":"pradeep"}'

use option -i instead of x.


If you really want to submit the GET request with JSON in the body (say for an XHR request and you know the server supports processing the body on GET requests), you can:

curl -X GET \
  -H "Content-type: application/json" \
  -H "Accept: application/json" \
  -d '{"param0":"pradeep"}' \
  "http://server:5050/a/c/getName"

Most modern web servers accept this type of request.


If you want to send your data inside the body, then you have to make a POST or PUT instead of GET.

For me, it looks like you're trying to send the query with uri parameters, which is not related to GET, you can also put these parameters on POST, PUT and so on.

The query is an optional part, separated by a question mark ("?"), that contains additional identification information that is not hierarchical in nature. The query string syntax is not generically defined, but it is commonly organized as a sequence of = pairs, with the pairs separated by a semicolon or an ampersand.

For example:

curl http://server:5050/a/c/getName?param0=foo&param1=bar

GET takes name value pairs.

Try something like:

curl http://server:5050/a/c/getName/?param1=pradeep

or

curl http://server:5050/a/c/getName?param1=pradeep

btw a regular REST should look something like

curl http://server:5050/a/c/getName/pradeep If it takes JSON in GET URL, it's not a standard way.