programing

명령줄에서 JSON payload를 사용한HTTP-request/콜은 어떻게 합니까?

easyjava 2023. 2. 23. 23:09
반응형

명령줄에서 JSON payload를 사용한HTTP-request/콜은 어떻게 합니까?

명령줄에서 JSON 콜을 가장 쉽게 실행할 수 있는 방법은 무엇입니까?JSON을 호출하여 추가 데이터를 가져오는 웹 사이트를 가지고 있습니다.

Google Chrome에 표시된 요청 페이로드는 다음과 같습니다.

{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }

착신 JSON 데이터를 해석하는 것이 아니라 (가능하면) Linux 명령줄에서 콜을 실행하여 JSON 콘텐츠를 취득하는 것입니다.

wget도 사용할 수 있습니다.

wget -O- --post-data='{"some data to post..."}' \
  --header='Content-Type:application/json' \
  'http://www.example.com:9000/json'

부르기wget옵션으로-O를 제공하다-(사이의 공백은 무시되므로 다음과 같이 쓸 수도 있습니다.-O -그 가치로 인해 야기될 수 있는wgetHTTP 응답을 표준 출력에 직접 파일로 출력합니다.그 긴 옵션명은 다음과 같습니다.--output-document=file.

데이터가 POST라고 가정할 때 컬을 사용합니다.

curl -X POST http://example.com/some/path -d '{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }'

GET을 사용하여 데이터를 취득하고 있으며 바의 URL 파라미터를 송신할 필요가 없는 경우 실행하기만 하면 됩니다.curl http://example.com/some/path

사용할 수 있습니다.wget와 함께post-file도움이 될 것 같아서요

wget --post-file=[file] --header=Content-Type:application/json [URL]

내용을 파일에 보관할 수 있으며, 내용은 다음과 같이 전송됩니다.post데이터.

curl --request POST \
--url http://localhost:8099/someservice/services/boo \
--header 'authorization: Basic dkfhsdlepwmdseA==' \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--data '{"value": "24.127.1212.123"}'

보셨어요?커맨드 라인을 통해 HTTP GET/POST 요청을 원활하게 처리할 수 있습니다.

예: (GET 요청의 경우):

C:\WINDOWS>curl "http://search.twitter.com/search.json?q=twitterapi&result_type=
popular"
{"results":[{"from_user_id_str":"32316068","profile_image_url":"http://a2.twimg.
com/profile_images/351010682/twitblock_profile_normal.png","created_at":"Thu, 25
 Nov 2010 14:37:46 +0000","from_user":"twitblockapp","id_str":"7805146834669569"
,"metadata":{"result_type":"popular","recent_retweets":10},"to_user_id":null,"te
xt":"blocking and reporting functions are currently failing. @TwitterAPI have be
en notified. http://j.mp/id5w3m","id":7805146834669569,"from_user_id":32316068,"
geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href=&q
uot;http://twitter.com" rel="nofollow">Tweetie for Mac</a&g
t;"}],"max_id":9607558079713280,"since_id":0,"refresh_url":"?since_id=9607558079
713280&q=twitterapi","results_per_page":15,"page":1,"completed_in":0.012698,"sin
ce_id_str":"0","max_id_str":"9607558079713280","query":"twitterapi"}

언급URL : https://stackoverflow.com/questions/4315111/how-to-do-http-request-call-with-json-payload-from-command-line

반응형