Jump to content

Sending XML to another URL using PHP (cURL)


galvin

Recommended Posts

I'm trying to make this code send some simple XML to another URL using cURL but it keeps giving me "Bad Request (Invalid Number)".

 

Can anyone see anything obviously wrong with this code that might cause this error?

 

Personally (and I am a newbie), I don't see any line in the code where the actual XML (i.e. $xml) is sent to other URL.  Could that be the problem?  If I'm simply missing it, can someone explain to me where this code takes the $xml variable and sends it to the other URL.

 

It just seems to me like the $xml variable is given some data and then nothing is done with that variable.

 

Anyone?

 

 

<?php
$companyKey = '310846';
$server = 'http://67.202.202.153';


$xml = '<?xml version="1.0" encoding="utf-8"?>' .
       '<LeadImportDatagram>'.
           '<CompanyKey>' . $companyKey . '</CompanyKey>' .
           '<NotificationEmailTo>[email protected]</NotificationEmailTo>' .
           '<LeadInfo>';
   '<City>Osweeego</City>';
         '</LeadInfo>';
        '</LeadImportDatagram>';

if(substr($server, 0, 4) != 'http') $server = 'http://' . $server;
if(substr($server, -1) == '/') $server = rtrim($server, '/');

$curlConfig = array(
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true
);

$curl = curl_init($server . '/xml/importlead.asp');
curl_setopt_array($curl, $curlConfig);
$responseText = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if($httpCode !== 200) {
    echo 'Error sending XML: ' . $responseText;
    exit(0);
}

header('Location: thanks.php');
exit(0);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.