curl-and-php
Re: Curl XML and PHP
Date: Wed, 16 Mar 2005 13:29:16 -0800
Do you know what the server is expecting? Is it expecting 'raw' data or
is it expecting the 'variable=data' posted data?
If it is the second, you probably need to urlencode the variable=data.
I've hacked an example that I found somewhere to do this:
function varEncode($varArray)
{
$args = array();
foreach($varArray as $key => $value){
array_push($args,$key.'='.urlencode($value));
}
return implode('&',$args);
}
To encode it:
$urlstring =varEncode(array('id'=>'888','request'=>$xmlcontent));
Then you can post the $urlstring
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlstring);
--JJ--
Leonardo Santillán wrote:
>I can connect to the script but i get next error: "Missing xml request
>document". Its like the script is not getting correctly the xml string im
>sending to it. What could it be?
>Thanks,
>
>
>
>
>----- Original Message -----
>From: "Davor @ Velcom" <davor_at_velcom.com>
>To: "Programming PHP/CURL" <curl-and-php_at_cool.haxx.se>
>Sent: Wednesday, March 16, 2005 2:27 PM
>Subject: Re: Curl XML and PHP
>
>
>
>
>>Leonardo Santillán wrote:
>>
>>
>>
>>>Hi,
>>>
>>>Im trying to post a XML string to a secure server and get the XML
>>>response from it in a PHP variable but i cant make it.
>>>I'll appreciate any help.
>>>Thanks,
>>>
>>>Im using this code:
>>>
>>>$url = "https//www.server.com";
>>>$xmlcontent = "<?xml version=\"1.0\" ?>";
>>>$xmlcontent .= "<blah prod=\"ggg\">";
>>>$xmlcontent .= "<session><aaa><id>123</id>";
>>>$xmlcontent .= "<user><firstName>me</firstName></user></aaa>";
>>>$xmlcontent .= "</session>";
>>>$xmlcontent .= "</blah>";
>>>$data = "id=888$request=$xmlcontent";
>>>
>>>$result = shell_exec("curl -m 120 -d \"$data\" $url -L");
>>>echo $result;
>>>
>>>and/or
>>>
>>>$ch = curl_init();
>>>curl_setopt($ch, CURLOPT_URL,$url);
>>>curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
>>>
>>>
>> curl_setopt($ch, CURLOPT_HEADER, 0);
>> curl_setopt($ch, CURLOPT_POST, 1);
>>
>>
>>
>>>curl_setopt($ch, CURLOPT_TIMEOUT, 4);
>>>curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
>>>$result = curl_exec($ch);
>>>echo $result;
>>>
>>>
>>
>>
>>
>
>
>
>
>
>
>
Received on 2005-03-16