cURL changes passed post fields

cURL changes passed post fields

am 05.12.2007 16:45:46 von gentleJuggernaut

I am using curl to access a webservice. The webservice offers a
search and confirm. The search works great. on the confirm there is
a value that needs to be passed back to the webservice in order to
confirm. This value often contains '+%20' etc. Curl appears to be
changing these values to spaces. Is there a curl option that will
tell it not to encode the data, just pass it as is.

Here is the cURL code that I am working with:

$ch = curl_init ();
$fp = @fopen('out.txt','w');
$postdata = 'serviceRequest=' . $xml;
curl_setopt ($ch, CURLOPT_URL,$this->getGateway($test));
curl_setopt ($ch, CURLOPT_TRANSFERTEXT,true);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_VERBOSE, true);
curl_setopt ($ch, CURLOPT_TIMEOUT, $this->getTimeout($test));
@curl_setopt ($ch, CURLOPT_STDERR, $fp);
$result = curl_exec ($ch);
curl_close($ch);
@fclose($fp);

the variable $xml contains my well formed xml request (I have verified
this separately). When the server (represented by $this-
>getGateway($test)) receives my xml statement with altered text (when
I compare what the server receives with what I had prior to putting it
through cURL some of the data contained in the xml has been
reformatted with spaces in place of certain characters, referenced
above). This of course causes the confirmation to fail. Any help
would be appreciated.

NSM

Re: cURL changes passed post fields

am 05.12.2007 16:59:41 von luiheidsgoeroe

On Wed, 05 Dec 2007 16:45:46 +0100, gentleJuggernaut =
=

wrote:

> I am using curl to access a webservice. The webservice offers a
> search and confirm. The search works great. on the confirm there is
> a value that needs to be passed back to the webservice in order to
> confirm. This value often contains '+%20' etc. Curl appears to be
> changing these values to spaces. Is there a curl option that will
> tell it not to encode the data, just pass it as is.
>
> Here is the cURL code that I am working with:
>
> $ch =3D curl_init ();
> $fp =3D @fopen('out.txt','w');
> $postdata =3D 'serviceRequest=3D' . $xml;

Hmmz, shouldn't you 'double encode' the data in the $xml here? Once some=
=

possible values/attributes in the XML itself, once the whole lot to make=
=

it postdata? (just guessing here, might work though). So, something like=
=

$postdata =3D 'serviceRequest=3D' . rawurlencode($xml);

> the variable $xml contains my well formed xml request (I have verified=

> this separately). When the server (represented by $this-
>> getGateway($test)) receives my xml statement with altered text (when
> I compare what the server receives with what I had prior to putting it=

> through cURL some of the data contained in the xml has been
> reformatted with spaces in place of certain characters, referenced
> above). This of course causes the confirmation to fail. Any help
> would be appreciated.
-- =

Rik Wasmus

Re: cURL changes passed post fields

am 05.12.2007 17:06:12 von gentleJuggernaut

On Dec 5, 10:59 am, "Rik Wasmus" wrote:
> On Wed, 05 Dec 2007 16:45:46 +0100, gentleJuggernaut
> wrote:
>
> > I am using curl to access a webservice. The webservice offers a
> > search and confirm. The search works great. on the confirm there is
> > a value that needs to be passed back to the webservice in order to
> > confirm. This value often contains '+%20' etc. Curl appears to be
> > changing these values to spaces. Is there a curl option that will
> > tell it not to encode the data, just pass it as is.
>
> > Here is the cURL code that I am working with:
>
> > $ch = curl_init ();
> > $fp = @fopen('out.txt','w');
> > $postdata = 'serviceRequest=' . $xml;
>
> Hmmz, shouldn't you 'double encode' the data in the $xml here? Once some
> possible values/attributes in the XML itself, once the whole lot to make
> it postdata? (just guessing here, might work though). So, something like
> $postdata = 'serviceRequest=' . rawurlencode($xml);
>
> > the variable $xml contains my well formed xml request (I have verified
> > this separately). When the server (represented by $this-
> >> getGateway($test)) receives my xml statement with altered text (when
> > I compare what the server receives with what I had prior to putting it
> > through cURL some of the data contained in the xml has been
> > reformatted with spaces in place of certain characters, referenced
> > above). This of course causes the confirmation to fail. Any help
> > would be appreciated.
>
> --
> Rik Wasmus


Thank you Rik, that is exactly what I needed. I am somewhat new to
passing data to webservices, I am going to look up the rawurlencode()
function, is there any other information that you could point me to?

Thanks again.

NSM

Re: cURL changes passed post fields

am 05.12.2007 17:22:03 von luiheidsgoeroe

On Wed, 05 Dec 2007 17:06:12 +0100, gentleJuggernaut =
=

wrote:
> On Dec 5, 10:59 am, "Rik Wasmus" wrote:
>> On Wed, 05 Dec 2007 16:45:46 +0100, gentleJuggernaut m>
>> wrote:
>>
>> > I am using curl to access a webservice. The webservice offers a
>> > search and confirm. The search works great. on the confirm there =
is
>> > a value that needs to be passed back to the webservice in order to
>> > confirm. This value often contains '+%20' etc. Curl appears to be=

>> > changing these values to spaces. Is there a curl option that will
>> > tell it not to encode the data, just pass it as is.
>>
>> > Here is the cURL code that I am working with:
>>
>> > $ch =3D curl_init ();
>> > $fp =3D @fopen('out.txt','w');
>> > $postdata =3D 'serviceRequest=3D' . $xml=
;
>>
>> Hmmz, shouldn't you 'double encode' the data in the $xml here? Once s=
ome
>> possible values/attributes in the XML itself, once the whole lot to m=
ake
>> it postdata? (just guessing here, might work though). So, something l=
ike
>> $postdata =3D 'serviceRequest=3D' . rawurlencode($xml);
>>
>> > the variable $xml contains my well formed xml request (I have verif=
ied
>> > this separately). When the server (represented by $this-
>> >> getGateway($test)) receives my xml statement with altered text (wh=
en
>> > I compare what the server receives with what I had prior to putting=
it
>> > through cURL some of the data contained in the xml has been
>> > reformatted with spaces in place of certain characters, referenced
>> > above). This of course causes the confirmation to fail. Any help
>> > would be appreciated.
>
> Thank you Rik, that is exactly what I needed. I am somewhat new to
> passing data to webservices, I am going to look up the rawurlencode()
> function, is there any other information that you could point me to?

Well, it helps to understand the underlying principle of HTTP requests:
http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1
http://www.jmarshall.com/easy/http/#postmethod

However, using webservices, a whole lot of other encoding besides =

application/x-www-form-urlencoded are possible. Having just the XML as r=
aw =

data in the request (so no classic form name/value pairs) is quite commo=
n. =

While fiddling around, testing/viewing your own post request can be quit=
e =

easy using php://input ()=
=

for reading the 'raw' input and/or apache_request_headers() to check the=
=

request headers (if you're running apache offcourse).
-- =

Rik Wasmus

Re: cURL changes passed post fields

am 05.12.2007 18:40:24 von AnrDaemon

Greetings, gentleJuggernaut.
In reply to Your message dated Wednesday, December 5, 2007, 19:06:12,

> Thank you Rik, that is exactly what I needed. I am somewhat new to
> passing data to webservices, I am going to look up the rawurlencode()
> function, is there any other information that you could point me to?

http_build_query will help.


--
Sincerely Yours, AnrDaemon