Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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...

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

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:

$ ./curl.bash 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <CalcPrimeFactorsResponse xmlns="http://www.mathertel.de/S01_AsyncSamples/">
      <CalcPrimeFactorsResult>2 3 3 5 3607 3803</CalcPrimeFactorsResult>
    </CalcPrimeFactorsResponse>
  </soap:Body>
</soap:Envelope>

A better method?

curl provides the following construct which can be used to pass options into it:

#!/bin/bash

{ echo '--opt1'
  echo '--opt2'
  ...
} | curl --config -

So you could adapt the above like so:

#!/bin/bash

ENDPOINT="http://mathertel.de/AJAXEngine/S01_AsyncSamples/CalcService.asmx"
VALUE=1234567890

if [ -n "${1}" ]; then
    VALUE=${1}
fi

read -r -d '' DATA <<EOF
<?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

{
echo '--silent'
echo '--header "Content-Type: application/soap+xml; charset=utf-8"'
echo '--user-agent ""'
echo "--url ${ENDPOINT}"
echo '--data-binary @-'
echo "$DATA"
} | curl --config - | xmllint --format -

This construct makes it a little easier to parameterize the $DATA payloads so you could wrap the entire curl construct in a function and just pass it variables to include, for example.

share|improve this answer
    
I apologize for the late comment. Just checked out the nswer. You were quite right . I also installed the libxml2 utility for xmllint. Everything is working just perfectly now. Thanks for the informative answer. +1 and accepted. –  The Dark Knight Aug 28 '13 at 16:25
add comment

I don't know what shell you are using, but bash at least will crap out if you use \\ to continue a line. Try \ instead.

WRT xml delinting, just check what you have with an online validator (e.g. this one) and use it.

share|improve this answer
    
I am using bash and thanks, i will try out u r suggestions. –  The Dark Knight Aug 17 '13 at 14:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.