zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[Bash] Get value from the response

The from get value Bash response
2023-09-14 09:00:45 时间
curl http://127.0.0.1:10080/login -u user

It prints out the token.

{"token":"eyJhbGciOwefewwefwIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20iLCJleHAiOjE2NTM2NzYzMjYsImlhdCI6MTY1MzQxNzEyNiwiaXNzIjoiYXV0aC5zZXJ2aWNlIiwic3ViIjoidXNlciJ9.G7C077LbtoL_FJF3s6wv1iMVGAiU-5zXWYpeJOnMDSY"}

You can copy and paste the long token in to the next command manually, but copying long, wrapped lines in cloud shell is broken. To work around this, you can either copy the JWT token in pieces, or - more easily - by assigning the token to a shell variable as follows

On shell 2 - login and assign the value of the JWT to a variable

TOKEN=$(curl http://127.0.0.1:10080/login -u user | jq -r '.token')

Check that it worked:

echo $TOKEN