user10755408
user10755408

Reputation:

how can i call web services with curl with json param?

I'm programming in Java. I developed a test web service in which I pass a random json and the service returns me hello

Here the web service code:

@Path("test")
@GET
@Consumes(MediaType.APPLICATION_JSON)
public String test(@HeaderParam("token") String token, @QueryParam("array")String array)
{
    return "hello";
}

I call the service with curl

curl -v -H 'token:aaaa' 'http://140.145.1.2/clayapi/restservices/test?array=[{"name":"george","lastname":"ronney"}]';

message of error:

curl: (3) [globbing] illegal character in range specification at pos 60

I tried to add -g but it doesn't work .. how should I do?

Upvotes: 1

Views: 69

Answers (1)

cassiomolin
cassiomolin

Reputation: 130867

Use -G along with --data-urlencode:

curl -v -G 'http://example.org' \
    -H 'header:value' \
    --data-urlencode 'array=[{"name":"george","lastname":"ronney"}]'

From the documentation:

-G, --get

When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an HTTP GET request instead of the POST request that otherwise would be used. The data will be appended to the URL with a ? separator. [...]

--data-urlencode <data>

(HTTP) This posts data, similar to the other -d, --data options with the exception that this performs URL-encoding. [...]

Upvotes: 1

Related Questions