Created
November 13, 2013 14:48
-
-
Save sehugunin/7450283 to your computer and use it in GitHub Desktop.
simple php send xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Remote URL | |
$remoteUrl = 'http://production.ebureau.com/'; | |
// Dummy values, use the values from your form | |
$userId = selec00014; | |
$password = 'xz82cc52fy59'; | |
$sid = 'xtech:verify:phone:1'; | |
$realtime = 1; | |
$protocol = 1; | |
$timeout = 5; | |
$phone = 9136316506; | |
$sourceId = 12345; | |
$subUserId = 'A&H'; | |
// Posting with cURL | |
$requestData = new SimpleXMLElement('<root></root>'); | |
$loginData = $requestData->addChild('login'); | |
$loginData->addChild('userid', $userId); | |
$loginData->addChild('password', $password); | |
$loginData->addChild('sid', $sid); | |
$loginData->addChild('realtime', $realtime); | |
$loginData->addChild('protocol', $protocol); | |
$loginData->addChild('timeout', $timeout); | |
$transactionData = $requestData->addChild('transaction'); | |
$inputData = $transactionData->addChild('input'); | |
$accountData = $inputData->addChild('account'); | |
$accountData->addChild('sourceid', $sourceId); | |
$accountData->addChild('subuserid', htmlentities($subUserId)); | |
$dataData = $inputData->addChild('data'); | |
$dataData->addChild('phone', $phone); | |
//header('Content-type: text/xml; charset=utf-8'); | |
$xmlContent = $requestData->asXML(); | |
echo $xmlContent; | |
// Send data | |
$ch = curl_init(); | |
// set URL and other appropriate options | |
$options = array(CURLOPT_URL => $remoteUrl, | |
CURLOPT_HEADER => false, | |
CURLOPT_RETURNTRANSFER => TRUE, | |
CURLOPT_POST => TRUE, | |
CURLOPT_POSTFIELDS => $xmlContent | |
); | |
curl_setopt_array($ch, $options); | |
// grab URL and pass it to the browser | |
$responseData = curl_exec($ch); | |
var_dump($responseData); | |
// close cURL resource, and free up system resources | |
curl_close($ch); | |
//$responseXml = simplexml_load_string($responseData); | |
//echo strval($responseXml->message); | |
$responseXml = simplexml_load_string($responseData); | |
echo (string) $responseXml->transaction->output->message->message; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment