cURL and XML

cURL POST request header checks and more in Bash:

"This option is handy to use when you want to store the headers that an HTTP site sends to you. Cookies from the headers could then be read in a second curl invocation by using the -b, --cookie option! The -c, --cookie-jar option is a better way to store cookies."

For many requests, use a loop:

for i in "${IDS[@]}"
do
    :
    if curl -D - -X POST www.google.com -o /dev/null | grep 'HTTP/1.1 200 OK'
done

There's probably a more eloquent way to grep...

curl -s -D - -X POST www.google.com -o /dev/null | head -n 1 | grep 200

XML

-d = data and thus <XML><Stuff><ID>'$1'</ID></Stuff></XML>

-H content-type: text/xml is also needed.

bash functions that return interpolated strings:

xml_return () {
echo '<Foo xmlns="foobar" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Attendant><ID xmlns="foobar">'$1'</ID><ServiceStatus>CLEANING_STARTED</ServiceStatus></Foo>'
}

keep the format by surrounding the parameter in single quotes.

Bash does not have hash maps, but it's doable. You know, this reminds me, I really need to read up on bash scripting...

back to index

site last updated: Fri Dec 6 16:29:06 2019