Forum Moderators: coopster
Trouble is, instead of printing the response, it prints my PHP code.
I think the trouble is the way my string literal is formed- I need to escape something (it contains a ?> among other things), but I'm not sure how to do it. I tried putting a backslash \ before a few characters in the string but it produced the same response.
Here is the code:
<html>
<body>
<?php
function httpsPost($Url, $strRequest)
{
// Initialisation
$ch=curl_init();
// Set parameters
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_URL, $Url);
// Return a variable instead of posting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Active the POST method
curl_setopt($ch, CURLOPT_POST, 1) ;
// Request
curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// execute the connexion
$result = curl_exec($ch);
// Close it
curl_close($ch);
return $result;
}
$url = 'https://example.com/wps2/location';
$strRequest =utf8_encode("<?xml version='1.0'?><LocationRQ xmlns='http://example.com/wps/2005' version='2.6' street-address-lookup='full'><authentication version='2.0'><simple><username>beta</username><realm>js.loki.com</realm> </simple></authentication><access-point><mac>00AA11BB22CC</mac><signal-strength>-50</signal-strength></access-point></LocationRQ>");
$Response = httpsPost($url, $strRequest);
echo $Response;
?>
</body>
</html>
And the response (in Firefox and IE):
example.com00AA11BB22CC-50"); $Response = httpsPost($url, $strRequest); echo $Response; ?>
Thanks for any help. :)
[edited by: eelixduppy at 7:59 pm (utc) on Feb. 2, 2009]
[edit reason] exemplified [/edit]
To make sure, look at the page source when getting response.
Or alternatively, replace "$strRequest =utf8_encode" with
$strRequest = htmlspecialchars(utf8_encode" to see the full output in the browser window.
Hope that helps!
When I view the source of the page, this is what I get:
<html>
<body>
<?php
function httpsPost($Url, $strRequest)
{
// Initialisation
$ch=curl_init();
// Set parameters
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_URL, $Url);
// Return a variable instead of posting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Active the POST method
curl_setopt($ch, CURLOPT_POST, 1) ;
// Request
curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// execute the connexion
$result = curl_exec($ch);
// Close it
curl_close($ch);
return $result;
}
$url = 'https://example.com/wps2/location';
$strRequest = htmlspecialchars( utf8_encode("<?xml version='1.0'?><LocationRQ xmlns='http://example.com/wps/2005' version='2.6' street-address-lookup='full'><authentication version='2.0'><simple><username>beta</username><realm>example.com</realm></simple></authentication><access-point><mac>00AA11BB22CC</mac><signal-strength>-50</signal-strength></access-point></LocationRQ>") );
$Response = httpsPost($url, $strRequest);
echo $Response;
?>
</body>
</html>
What's interesting to note is that the whole <?php section appears in pink (using Firefox) until I get to <LocationRQ xmlns='http://example.com/wps/2005'...
Then it is colored as HTML. So maybe FF thinks the XML code is HTML?
Apparantly my server isn't parsing it as PHP.
[edited by: eelixduppy at 2:10 am (utc) on Feb. 3, 2009]
[edit reason] example.com [/edit]