cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: cURLing XML

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Fri, 21 Nov 2003 08:37:06 +0100 (CET)

On Thu, 20 Nov 2003, Stephen Buckley wrote:

> First off I'm new to cURL and I've many questions.

Welcome to our merry corner of the universe!

> I'm trying to utilize cURL to send XML data(as a long string) with
> CURLOPT_POSTFIELDS as:
>
> curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml_data);
>
> but the data that gets sent is all just a name/value pair array, thus
> mangling the XML text that the target server is expecting.

Uh? You're sendinf an XML blob and it is sent as "a name/value pair array" ?
How on earth can it do that?

Can you describe this other words or possibly showing us some source code of
yours that show how you create this xml data variable?

> Also, the application that is receiving this data, as specified by the
> company, needs the header items of the data to be set as the following:
>
> curl_setopt($ch, CURLOPT_HTTPHEADER, array('POST / AUTHORIZE HTTP/1.0',
> 'MIME-Version: 1.0', 'Content-type: application/PTI21', 'Content-length:
> value='.$ReqLen, 'Content-transfer-encoding: text', 'Request-number: 1',
> 'Document-type: Request');

I doubt they want *exactly* this, as you cannot provide the POST request like
that as a header. The request itself is not a header and thus it cannot be
modified with CURLOPT_HTTPHEADER.

Are you actually saying you want to send 'POST / AUTHORIZE HTTP/1.0' as a
request? It is a horrible violation of what HTTP is. Is't it supposed to be
'POST /AUTHORIZE HTTP/1.0' ?

Also, I would recommend you to NOT attempt to fiddle with Content-length
yourself, as you only risk shooting yourself in the foot. curl is perfectly
capable of setting this correctly itself.

> I wasn't sure if anything here, specifically the 'Content-type', was the
> cause for cURL messing up the XML string.

curl doesn't mess it up, curl doesn't touch or fiddle with it at all. It
passes along *exactly* what you passed on to it. If there's any "messing up"
going on, it is made by your PHP program or something.

In what way is the data messed up? Are you sure you don't need to encode it
somehow for the server to like it?

> I've also seen in a previous post about trying:
>
> curl_setopt ($ch, CURLOPT_POSTFIELDS, "<post field name>=<xml data>");
>
> But that doesn't seem to work either.

You don't seem to know what kind of data your server-end expects?

As usual, I recommend using the curl command line tool to work things out,
when it works you convert the command line to a PHP program.

> I've noticed via other posts, that there are cURL C libraries that offer the
> FormAdd functionality which seems to get around this,

What makes you believe curl_formadd() would work around your problem?

> but I don't think C is an option. Is there a workaround?

For doing what?

> Also, am I going to have to urlencode the XML data that would get sent?

I don't know. I know curl won't do it for you.

-- 
    Daniel Stenberg -- http://curl.haxx.se/ -- http://daniel.haxx.se/
 [[ Do not post private mails to this email address. They won't reach me. ]]
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Received on 2003-11-21