Stuck on Posting XML

My hands are sore! I’ve tried solving this for 2 days, and I’ve read about 20 web sites on the topic, no luck!

Can anyone see something obviously wrong with my XML or my Headers?


<?php

$url = "https://b2b.rci.com/variableduration/gateway";

$post_string = '<?xml version="1.0" encoding="UTF-8"?>
<requestEnvelope>
	<requestHeader>
		<controlData>
			<clientName>XMLBusinessPartnerChannel</clientName>
			<userID>PRIVATE</userID>
			<password>PRIVATE</password>
		</controlData>
		<processData>
			<operationName>quickSearch</operationName>
		</processData>
	</requestHeader>
	<SearchRequest>
		<startDate>11/4/2010</startDate>
		<endDate>12/30/2010</endDate>
		<lengthOfStay>7</lengthOfStay>
		<minUnitSize>H</minUnitSize>
		<regionCode>FLSE</regionCode>
	</SearchRequest>
</requestEnvelope>';



$header  = "POST HTTP/1.0 \\r\
";
$header .= 'WWW-Authenticate: Basic realm="CVC"';
$header .= 'Authorization: '.base64_encode('PRIVATE:PRIVATE');
$header .= "Content-type: text/xml \\r\
";
$header .= "Content-length: ".strlen($post_string)." \\r\
";
//$header .= "Content-transfer-encoding: text \\r\
";
$header .= "Connection: close \\r\
\\r\
"; 

$header .= $post_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

$data = curl_exec($ch); 

if(curl_errno($ch))
    print curl_error($ch);
else
    curl_close($ch);

print_r($data);
?>

All attempts I make return the vendors error code 8055, with message ‘User Authentication Failed’.

I’d forget about the HTTP error code for now, the server obviously isn’t RESTful.

If I send over a different XML payload, I get error code 2134 and message ‘Error processing request’.

My best guess (without valid credentials) is that the following should get you a little further, if not there.

:slight_smile:

Good luck!


<?php
error_reporting(-1);
ini_set('display_errors', true);

$payload = '<requestEnvelope>
    <requestHeader>
        <controlData>
            <clientName>XMLBusinessPartnerChannel</clientName>
            <userID>PRIVATE</userID>
            <password>PRIVATE</password>
        </controlData>
        <processData>
            <operationName>quickSearch</operationName>
        </processData>
    </requestHeader>
    <SearchRequest>
        <startDate>11/4/2010</startDate>
        <endDate>12/30/2010</endDate>
        <lengthOfStay>7</lengthOfStay>
        <minUnitSize>H</minUnitSize>
        <regionCode>FLSE</regionCode>
    </SearchRequest>
</requestEnvelope>';

$handle = curl_init();

curl_setopt_array(
    $handle,
    array(
        CURLOPT_URL             => 'https://b2b.rci.com/variableduration/gateway',
        CURLOPT_POST            => true,
        CURLOPT_POSTFIELDS      => 'serviceRequest=' . $payload,
        CURLOPT_RETURNTRANSFER  => true,
        CURLOPT_USERPWD         => sprintf('%s:%s', 'anthony', 'password'),
        CURLOPT_HTTPAUTH        => CURLAUTH_BASIC | CURLAUTH_ANY,
        CURLOPT_SSL_VERIFYPEER  => false,
    )
);

$response = curl_exec($handle);
?>

$url is https but you’re not logged in?

Isn’t that what you do with the authorization here?


$header .= 'Authorization: '.base64_encode('PRIVATE:PRIVATE');

It looks like it should but maybe not?
http://theserverpages.com/php/manual/en/function.curl-setopt.php

A custom request method to use instead of “GET” or “HEAD” when doing a HTTP request. This is useful for doing “DELETE” or other, more obscure HTTP requests. Valid values are things like “GET”, “POST”, “CONNECT” and so on; i.e. Do not enter a whole HTTP request line here. For instance, entering "GET /index.html HTTP/1.0\r
\r
" would be incorrect.

Note: Don't do this without making sure your server supports the custom request method first.

$header .= 'WWW-Authenticate: Basic realm="CVC"';
$header .= 'Authorization: '.base64_encode('PRIVATE:PRIVATE');

Should these not have a set of CRLF ?

Additionally, I’ve never had the need to implement the CURLOPT_CUSTOMREQUEST cUrl option, you may need to investigate that.

Here’s a little more standard way of doing things. :wink:


<?php
error_reporting(-1);
ini_set('display_errors', true);

$handle = curl_init();

curl_setopt_array(
    $handle,
    array(
        CURLOPT_URL             => 'https://b2b.rci.com/variableduration/gateway',
        CURLOPT_POST            => true,
        CURLOPT_POSTFIELDS      => '<here><be><my><xml><payload>heya!</payload></xml></my></be></here>',
        CURLOPT_RETURNTRANSFER  => true,
        CURLOPT_USERPWD         => sprintf('%s:%s', 'anthony', 'password'),
        CURLOPT_HTTPAUTH        => CURLAUTH_BASIC | CURLAUTH_ANY,
    )
);

$response = curl_exec($handle);
?>

You can additionally headers by implementing the CURLOPT_HTTPHEADER option and passing it an array.

Should these not have a set of CRLF ?

Most examples I’ve seen don’t use these, but I have tried with and without it it appears they don’t make much difference.

Wow I never seen that URL, cool wish it was in their docs!
I can get the XML to work through that test page, but not on the other page.

With the same XML that will work on the test page, I can’t get it to go through here:
http://www.condovacationclub.com/development/resortviewer/REST_testing.php

The server response seems to indicate Im getting through, but if i put in bad credentials it doesnt seem to care and still gives me a http 200.

Thanks guys, I have been reading up on this stuff. I haven’t had trouble with cURL for other services like yahoo, but this ones a little tricky hehehe :slight_smile:

So, did it work? I noticed this page, which posts to the same URL, asks you to omit the XML declaration and passes the payload with the serviceRequest index.

You have helped me get it working! Please check your email (the mail @ anthony … address) :smiley:

Of course I did, you doubted me? Shame on you. :cool:

Off Topic:

I appreciate your offer, I really do. How about the next time I’m in your neck of the woods, you buy me a nice coffee instead huh?

So, until that coffee …

Anthony.

Haha okay sounds good haha funny guy