Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

rest - Curl GET request with json parameter

I am trying to send a "GET" request to a remote REST API from Command Prompt via cURL like this:

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

But it returns no output. I tried to ping the URL directly from the browser, I am able to get response successfully, I don't understand what is the wrong with the command.

Basically I want to set a "GET" request to a remote REST service which gives me json data as a response via curl. Can anyone guide me what mistake am I doing? I tried various posts, but all of them talk about POST requests not about GET.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This should work :

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

use option -i instead of x.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...