tags:

views:

315

answers:

2

Is there a reason why a PHP cURL enblaed server will refuse to display xml responses? I have been working on a script to post numbers to a dialling service. I felt using cURL would be the best thing to do.

On 3 different servers, each running different versions of PHP, I am able to get responses with no problems. But on the particular server, no matter how many times I try, I just get a blank response.

This the script in question:

<?php
if ($_POST['request_callback'])
{
$customer_name      = cleaninput($_REQUEST['customer_name'],"text");
$debtor_id          = cleaninput($_REQUEST['debtor_id'],"number");
$telephone_number   = cleaninput($_REQUEST['customer_number'],"number");

$xml_request = '<?xml version="1.0" encoding="utf-8"?>';
$xml_request .= '<CallRequest>';
$xml_request .= '<ProjectName>Noble Test</ProjectName>';
$xml_request .= '<ContactNumberToDial>'.$telephone_number.'</ContactNumberToDial>';
if (isset($_POST['callme_now'])) {
    $xml_request .= '<DateTimeToDial></DateTimeToDial>';
} else {
    $xml_request .= '<DateTimeToDial>' . date('Y-m-d ' . $_POST['hour_select'] . ':' . $_POST['minute_select'] . ':s') . '</DateTimeToDial>';
}
$xml_request .= '<ListSource>WebLead</ListSource>';
$xml_request .= '<AgentName></AgentName>';
$xml_request .= '<AddToList>False</AddToList>';
$xml_request .= '<SpecificAgent>False</SpecificAgent>';
$xml_request .= '<DBField>';
$xml_request .= '<FieldName>Name</FieldName>';
$xml_request .= '<FieldValue>NobleTesting</FieldValue>';
$xml_request .= '</DBField>';
$xml_request .= '</CallRequest>';

$loginUsername = "username";
$loginPassword = "password";
//$user_agent    = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

// Send using CURL
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://194.217.1.2/ClickToCall/CallRequest.asmx/Call");          // URL to post
//curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_USERPWD, "$loginUsername:$loginPassword"); //login
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// curl_setopt( $ch, CURLOPT_HEADER, 1);  // make sure we get the header
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'xmlString=' . urlencode($xml_request));
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt( $ch, CURLINFO_HEADER_OUT, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec( $ch ); // runs the post
curl_close($ch);

}
?>

This runs well everywhere else but this particular server where a response is not sent back. I have also used Firebug to check the request and response headers and both turned out to be empty.

Can anyone help out?

Thanks

James

A: 

Try this to ensure the 4th box is actually setup properly to serve web pages:

From a command line terminal :

$ telnet 194.217.1.2 80  (press enter)

You should get a response like :

Trying 192.168.245.84... Connected to 194.217.1.2. Escape character is '^]'.

Type this in:

GET /ClickToCall/CallRequest.asmx/Call HTTP/1.1 (press enter)
Host: 194.217.1.2 (press enter twice)

You should get a response sort of like this with different HTML info likely:

HTTP/1.1 200 OK Date: Wed, 16 Dec 2009 15:40:13 GMT Server: Apache/1.3.31 (Unix) PHP/4.3.8 X-Powered-By: PHP/4.3.8 Transfer-Encoding: chunked Content-Type: text/html

248

Network Quality Assurance Homepage Some stuff here

Justin
A: 

Anyway I have discovered the solution to the problem. It seems the dialling server did not accept transfers that started with HEAD request. I ended up having to modify some portions of my script to make use of the CURLOPT_CUSTOMREQUEST with GET.

At least this time, I am receiving a response. So that has done the trick.

James