curl命令 get写法总结

1、生成文件方式:

declare getredisurl='/api/test-service/sys/gettesturl'

echo curl -i -X GET -H "'Content-type':'application/json'" 'http://'$nacosServer':8089'$getredisurl > ./temp.log
cat ./temp.log >> info.log
source ./info.log > result
code=$(cat result | sed 's/,/\n/g' | grep "code" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g'| sed 's/"//g')

#获取get请求,返回code
echo 'authority:'$code
cat result >> info.log
rm -rf ./info.log
rm -rf ./temp.log

2、其他方式:

declare token='/api/test1-service/common/getdefaulttoken'
declare testurl='/api/test2-service/test/client'

defaultToken=$(curl --location --silent --request GET "http://"$nacosServer":8089"$token | sed 's/,/\n/g' | grep "data" | sed 's/}//g' | sed 's/{//g' | sed 's/:/\n/g' | sed '1d' | sed '1d' | sed 's/"//g' )
echo $defaultToken
testresult=$(curl -X GET 'http://'$nacosServer':8089'$testurl -H 'cache-control: no-cache' -H 'token: '$defaultToken | sed 's/,/\n/g' | grep "code" | sed 's/{//g' | sed 's/:/\n/g' | sed '1d')
echo $testresult

3、可换行【\】:

curl -X GET \
  'http://'$nacosServer':8089'$testurl \
  -H 'cache-control: no-cache' \
  -H 'token: '$defaultToken 

你可能感兴趣的:(Linux,Java,cmd,java,开发语言)