php n xml

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gingar
Forum Newbie
Posts: 3
Joined: Fri Oct 20, 2006 3:47 am

php n xml

Post 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:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php n xml

Post 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
gingar
Forum Newbie
Posts: 3
Joined: Fri Oct 20, 2006 3:47 am

Re: php n xml

Post 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*
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php n xml

Post 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.
gingar
Forum Newbie
Posts: 3
Joined: Fri Oct 20, 2006 3:47 am

Re: php n xml

Post by gingar »

tasairis, i pmed u. :D
Post Reply