I have been trying to invoke a web service from my script using the Curl
command . I got the script from HERE.
My Script :
#! /bin/sh
ENDPOINT="http://mathertel.de/AJAXEngine/S01_AsyncSamples/CalcService.asmx"
VALUE=1234567890
if [ -n "${1}" ]; then
VALUE=${1}
fi
curl --silent \\
--data \\
@- \\
--header 'Content-Type: application/soap+xml; charset=utf-8' \\
--user-agent "" \\
${ENDPOINT} <<EOF | xmllint --format -
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<CalcPrimeFactors xmlns="http://www.mathertel.de/S01_AsyncSamples/">
<inputText>${VALUE}</inputText>
</CalcPrimeFactors>
</soap12:Body>
</soap12:Envelope>
EOF
And i get these Errors :
./CalcService.sh: 10: ./CalcService.sh: --data: not found
./CalcService.sh: 11: ./CalcService.sh: @-: not found
./CalcService.sh: 12: ./CalcService.sh: --header: not found
./CalcService.sh: 13: ./CalcService.sh: --user-agent: not found
./CalcService.sh: 14: ./CalcService.sh: ./CalcService.sh: 14: ./CalcService.sh: http://mathertel.de/AJAXEngine/S01_AsyncSamples/CalcService.asmx: not found
xmllint: not found
Now i have installed curl, and tried to install xmllint
but it did not get installed, saying it's a broken package.
Anybody has any suggestions as to what is happening here and what i can do to mitigate this ? This is driving me crazy…
Best Answer
As @goldilocks suggested, taking out the double back slashes (
\\
) and replacing them with single backslashes (\
) appears to fix your issue. Here's an example of the output with the modifications:A better method?
curl
provides the following construct which can be used to pass options into it:So you could adapt the above like so:
This construct makes it a little easier to parameterize the
$DATA
payloads so you could wrap the entirecurl
construct in a function and just pass it variables to include, for example.