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>joeschmoe@gmail.com</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);
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.