Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL GET query string is a JSON

Tags:

json

http

curl

I am try to access the remote RESTful Services API using cURL, the query string parameter has a JSON value. My cURL command like:

curl -g -i 'http://localhost:8080/context/restdev/employees/?q={"deptno":{"$lte":20}}'

If I enter the URL in the Chrome, I can get the data back. My cURL command gets: The URI is not well-formed, reason: Illegal character in query at position: 48

like image 821
user2018791 Avatar asked Mar 23 '16 08:03

user2018791


1 Answers

Your query

q={"deptno":{"$lte":20}}'

needs to be percent encoded. cURL supports that with the --data-urlencode switch, so try this (one line):

curl -G -i "http://localhost:8080/context/restdev/employees/" 
--data-urlencode 'q={"deptno":{"$lte":20}}'
like image 167
RamblinRose Avatar answered Oct 18 '22 17:10

RamblinRose