Page 1 of 1

php n xml

Posted: Thu Dec 18, 2008 7:19 pm
by gingar
At present, i'm using curl. I am able to send the xml query over, and get a response. but the response is not what i am expecting.

This is the code im using..

Code: Select all

 
$url = "http://xxx";
$xml = '<?xml version ="1.0" encoding="UTF-8"?>
         <root>
            <header>
               <protocol>1</protocol>
               <oem>xx</oem>
               <agentID>xxx</agentID>
               <password>xxxx</password>
            </header>
            <body>
               <opCode>XX_AREAS_XX</opCode>
               <item name=”ANTALYA” ID=”5” />
               <item name=”JERUSALEM” ID=”1” />
            </body>
 
         </root>
      ';
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml=' . $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch); #this returns html
 
when i use a standalone program to submit the exact same xml string to the same url, using post, i get this reply.

Code: Select all

<body><version>3.91</version><opCode>OP_AREAS_LIST</opCode><country ID="27"><item name="Aachen, Germany" ID="13547" coreID="0"/><item name="Augsburg, Germany" ID="4408" coreID="0"/><item name="Bad Homburg, Germany" ID="5867" coreID="0"/><item name="Baden-Baden, Germany" ID="229" coreID="0"/><item name="Bautzen, Germany" ID="5889" coreID="0"/></country></body>
 
but when i use the above code, i get this instead..

Code: Select all

 
<body><version>3.91</version><opCode>OP_OK</opCode></body>
 
is there something wrong with the way i'm executing the code? :banghead:

Re: php n xml

Posted: Thu Dec 18, 2008 8:08 pm
by requinix
I don't think it's the problem, but you use Unicode quotes in your XML. Try using plain-old " quotes, or run $xml through utf8_encode().
Also, you should be running $xml through urlencode regardless of what's inside.

Code: Select all

$url = "http://xxx";
$xml = '<?xml version ="1.0" encoding="UTF-8"?>
         <root>
            <header>
               <protocol>1</protocol>
               <oem>xx</oem>
               <agentID>xxx</agentID>
               <password>xxxx</password>
            </header>
            <body>
               <opCode>XX_AREAS_XX</opCode>
               <item name="ANTALYA" ID="5" />
               <item name="JERUSALEM" ID="1" />
            </body>
 
         </root>
      ';
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml=' . urlencode($xml));
// or leave the ” quotes you had before and use
//curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml=' . urlencode(utf8_encode($xml)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch); #this returns html

Re: php n xml

Posted: Thu Dec 18, 2008 8:30 pm
by gingar
thanks for your reply tasairis,

but i still get the same one line reply as before.

I swapped the " with ' and the ' with ". But still the same.

i also tried

Code: Select all

 
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 
// Optionally set a timeout
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml=' . urlencode(utf8_encode($xml)));
$content = curl_exec($ch);
 
but no difference.. *pull hair*

Re: php n xml

Posted: Thu Dec 18, 2008 9:49 pm
by requinix
I'm willing to do a bit of research but you'd need to say where this request goes. Like what website, the service name, stuff like that.

Re: php n xml

Posted: Thu Dec 18, 2008 11:40 pm
by gingar
tasairis, i pmed u. :D