In Linux, we can use curl post json to send data. The sent json data sometimes needs to obtain variables. Normally, it is written in Linux Shell script Variables are used in. For example, you can obtain variables by directly writing the $var variable name, but obtaining json data involves punctuation, leading to the problem that json data variables cannot be obtained. For example, the following code is an example of curl post json.
$TITLE="Nice weather" $CONTENT="It's a nice day today. Lan Ye is going out for a walk." curl -X POST -H "Content-Type: application/json" -d '{"title":"$TITLE","content":"$CONTENT"}' https://lanye.org/addLog. php
In the above shell script example, the variables in the json data cannot be obtained. That is because there is a difference between the use of single quotation marks and double quotation marks under Linux. Here, the single quotation marks are used to directly output the contents of the json data. How to solve the problem that the linux shell curl post json data variables cannot be obtained? What is the solution to the problem that the linux shell curl post json data variables cannot be obtained?
Linux shell curl post json data variable cannot be obtained. The solution is simple. Just include the variable in single quotation marks in the json data. The complete example is as follows.
curl -X POST -H "Content-Type: application/json" -d '{"title":"'$TITLE'","content":"'$CONTENT'"}' https://lanye.org/addLog.php
Disclaimer:
Website: Click Copy to share with friends!
All content resources shared by this website, if not noted, are original by Blueleaf. If you need to reprint, please indicate the source; Please contact us in case of infringement Contact handling 。 Please understand!