cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Howto question - SOAP on the command line

From: Dan White <ygor_at_comcast.net>
Date: Tue, 19 Apr 2005 22:09:03 -0400

Thanks for the response.

Here's some more detail:
This service returns television schedule and program listings in an XML
statement

The wget statement is this:
==========================
wget --debug --http-user='userid' --http-passwd='yourPassword'
--post-file='soap.xml' --header='Accept-Encoding:gzip'
http://datadirect.webservices.zap2it.com/tvlistings/xtvdService
--output-document=tv.gz
==========================
and the soap.xml file contains:
==========================
<?xml version='1.0' encoding='utf-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'>
        <SOAP-ENV:Body>
                <ns1:download xmlns:ns1='urn:TMSWebServices'>
                        <startTime xsi:type='xsd:dateTime'>2005-04-20T00:00:00</startTime>
                        <endTime xsi:type='xsd:dateTime'>2005-04-20T00:06:00</endTime>
                </ns1:download>
        </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
==========================
OK so far ?

Now, if I run the wget with full debug and other junk turned on, I get
this:
==========================
wget --debug --server-response --http-user='userid'
--http-passwd='password' --post-file='soap.xml'
--header='Accept-Encoding:gzip'
http://datadirect.webservices.zap2it.com/tvlistings/xtvdService
--output-document=tv.gz
DEBUG output created by Wget 1.9.1 on darwin7.9.0.

--21:22:02--
http://datadirect.webservices.zap2it.com/tvlistings/xtvdService
            => `tv.gz'
Resolving datadirect.webservices.zap2it.com... 206.18.98.160
Caching datadirect.webservices.zap2it.com => 206.18.98.160
Connecting to datadirect.webservices.zap2it.com[206.18.98.160]:80...
connected.
Created socket 5.
Releasing 0x508590 (new refcount 1).
---request begin---
POST /tvlistings/xtvdService HTTP/1.0
User-Agent: Wget/1.9.1
Host: datadirect.webservices.zap2it.com
Accept: */*
Connection: Keep-Alive
Authorization: Basic ljydtdgyf5t79870ryghuggi=
Content-Type: application/x-www-form-urlencoded
Content-Length: 571
Accept-Encoding:gzip

[writing POST file soap.xml ... done]
---request end---
HTTP request sent, awaiting response... HTTP/1.1 401 Unauthorized
Date: Wed, 20 Apr 2005 01:22:02 GMT

  2 Date: Wed, 20 Apr 2005 01:22:02 GMTServer: Orion/2.0.2

  3 Server: Orion/2.0.2Connection: Close

  4 Connection: CloseContent-Type: text/html

  5 Content-Type: text/htmlWWW-Authenticate: Digest
realm="TMSWebServiceRealm",
nonce="PDExMTM5NjAxMjMxNzcuNGJmY2Q3YTdiMDg5MjMzYzNhMDA4M2I3NmRmNzkzODZAc
HJpbWV0aW1lPg==", opaque="a064ab3c7afaa4cf", algorithm=MD5, qop="auth"

  6 WWW-Authenticate: Digest realm="TMSWebServiceRealm",
nonce="PDExMTM5NjAxMjMxNzcuNGJmY2Q3YTdiMDg5MjMzYzNhMDA4M2I3NmRmNzkzODZAc
HJpbWV0aW1lPg==", opaque="a064ab3c7afaa4cf", algorithm=MD5, qop="auth"

Closing fd 5
Found datadirect.webservices.zap2it.com in host_name_addresses_map
(0x508590)
Connecting to datadirect.webservices.zap2it.com[206.18.98.160]:80...
connected.
Created socket 5.
Releasing 0x508590 (new refcount 1).
---request begin---
POST /tvlistings/xtvdService HTTP/1.0
User-Agent: Wget/1.9.1
Host: datadirect.webservices.zap2it.com
Accept: */*
Connection: Keep-Alive
Authorization: Digest username="userid", realm="TMSWebServiceRealm",
nonce="PDExMTM5NjAxMjMxNzcuNGJmY2Q3YTdiMDg5MjMzYzNhMDA4M2I3NmRmNzkzODZAc
HJpbWV0aW1lPg==", uri="/tvlistings/xtvdService",
response="27b41196dda61ef84158df43f501b1fe", opaque="a064ab3c7afaa4cf"
Content-Type: application/x-www-form-urlencoded
Content-Length: 571
Accept-Encoding:gzip

[writing POST file soap.xml ... done]
---request end---
HTTP request sent, awaiting response... HTTP/1.1 200 OK
Date: Wed, 20 Apr 2005 01:22:04 GMT

  2 Date: Wed, 20 Apr 2005 01:22:04 GMTServer: Orion/2.0.2

  3 Server: Orion/2.0.2Connection: Close

  4 Connection: CloseContent-Type: text/xml; charset=utf-8

  5 Content-Type: text/xml; charset=utf-8Content-Encoding: gzip

  6 Content-Encoding: gzip

[<=> ] 0 --.--K/s
[ <=> ] 2,746 1.24K/s
[ <=>] 5,043 2.22K/s

Closing fd 5
21:22:07 (2.22 KB/s) - `tv.gz' saved [5043]
==========================
...and tv.gz contains a nicely gzipped XML statement.

==========================
...and now for what should be the equivalent "curl" command:
==========================
curl -v --trace-ascii - -u userid:password -d @soap.xml --compressed -o
theOutputFile
http://datadirect.webservices.zap2it.com/tvlistings/xtvdService

== Info: About to connect() to datadirect.webservices.zap2it.com:80
== Info: Connected to datadirect.webservices.zap2it.com (206.18.98.160)
port 80
=> Send header, 963 bytes (0x3c3)
0000: POST /tvlistings/xtvdService HTTP/1.1
0027: Authorization: Basic ljydtdgyf5t79870ryghuggi=
0056: User-Agent: curl/7.10.2 (powerpc-apple-darwin7.0) libcurl/7.10.2
0096: OpenSSL/0.9.7b zlib/1.1.4
00b2: Host: datadirect.webservices.zap2it.com
00db: Pragma: no-cache
00ed: Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
012f: Accept-Encoding: deflate
0149: Content-Length: 562
015e: Content-Type: application/x-www-form-urlencoded
018f:
0191: <?xml version='1.0' encoding='utf-8'?><SOAP-ENV:Envelope xmlns:S
01d1: OAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='h
0211: ttp://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/20
0251: 01/XMLSchema-instance' xmlns:SOAP-ENC='http://schemas.xmlsoap.or
0291: g/soap/encoding/'> <SOAP-ENV:Body> <ns1:download xmln
02d1: s:ns1='urn:TMSWebServices'> <startTime xsi:type='xsd:
0311: dateTime'>2005-04-20T00:00:00</startTime> <endTime xs
0351: i:type='xsd:dateTime'>2005-04-20T00:06:00</endTime> </ns1
0391: :download> </SOAP-ENV:Body></SOAP-ENV:Envelope>
<= Recv header, 23 bytes (0x17)
0000: HTTP/1.1 100 Continue
<= Recv header, 21 bytes (0x15)
0000: Server: Orion/2.0.2
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 20 Apr 2005 02:05:12 GMT
<= Recv header, 27 bytes (0x1b)
0000: HTTP/1.1 401 Unauthorized
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 20 Apr 2005 02:05:12 GMT
<= Recv header, 21 bytes (0x15)
0000: Server: Orion/2.0.2
<= Recv header, 19 bytes (0x13)
0000: Connection: Close
<= Recv header, 25 bytes (0x19)
0000: Content-Type: text/html
<= Recv header, 197 bytes (0xc5)
0000: WWW-Authenticate: Digest realm="TMSWebServiceRealm", nonce="PDEx
0040: MTM5NjI3MTMzNDAuM2NkY2Y3YmMyNTllYjM0MmUwYTNmYmViYjVhNWExZDZAcHJp
0080: bWV0aW1lPg==", opaque="b8300675610339ad", algorithm=MD5, qop="au
00c0: th"
<= Recv header, 28 bytes (0x1c)
0000: Transfer-Encoding: chunked
<= Recv data, 106 bytes (0x6a)
0000: 5f
0004: <HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD><BODY><H1>401
0044: Unauthorized</H1></BODY></HTML>
0065: 0
0068:
   % Total % Received % Xferd Average Speed Time
  Curr.
                                  Dload Upload Total Current Left
  Speed
100 95 0 95 0 0 152 0 --:--:-- 0:00:00
--:--:-- 0
== Info: Closing connection #0
==========================
...and all that is in the curl output is
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD><BODY><H1>401
Unauthorized</H1></BODY></HTML>

Now, what I see happening is wget receives the first response ("401
Unauthorized")
then it closes the socket, re-opens it, and THEN it get the XML.

I see curl bagging it after the first response ("401 Unauthorized") and
not picking up the XML which is sent next.

I can find nothing in the curl documentation to help out.

Does this help ?

On Apr 19, 2005, at 4:48 PM, Daniel Stenberg wrote:

> On Tue, 19 Apr 2005, Dan White wrote:
>
>> I would like to use curl (on a command line/in a script) to do the
>> equivalent of this wget command :
>>
>> wget --http-user='username' --http-passwd='password'
>> --post-file='soap.xml' --header='Accept-Encoding:gzip'
>> http://datadirect.webservices.zap2it.com/tvlistings/xtvdService
>> --output-document=outputFile.gz
>
> Without being a wget wizard, I would say that the curl equivalent
> would be:
>
> curl -u username:password -d @soap.xml --compressed -o outputFile
> http://datadirect.webservices.zap2it.com/tvlistings/xtvdService
>
> This would ask for a compressed response and automatically unpack it
> on retrieval and store the uncompressed version in the given output
> file (assuming curl was built with libz support enabled).
>
> People that sends XML often wants to change content-type as well, like
> -H "Content-Type: text/xml".
>
> Note that this makes a POST and it sends the file "raw" with no
> encoding done what so ever.
>
> Append --trace-ascii to see exactly what curl sends and receives.
>
>> Or should I just go straight to the library ?
>
> I recommend smoothing it out with the curl tool first, but that's
> mostly a matter of taste.
>
> Good luck!
>
> --
> Commercial curl and libcurl Technical Support:
> http://haxx.se/curl.html
>
Received on 2005-04-20