集成PHP Curl

集成PHP Curl,php,mysql,xml,http,php-curl,Php,Mysql,Xml,Http,Php Curl,下面的代码调用了一个MySQLi,并在浏览器中以XML形式显示它 下一个阶段是,我不想在浏览器中显示它,而是想使用PHP Curl将它发送到另一个IP地址。请有人能帮我做这件事所需的额外代码 <?php $mysqli_connection = new MySQLi('localhost', 'root', 'secret', 'edgeserver'); if ($mysqli_connection->connect_error) { echo "Not connected

下面的代码调用了一个MySQLi,并在浏览器中以XML形式显示它

下一个阶段是,我不想在浏览器中显示它,而是想使用PHP Curl将它发送到另一个IP地址。请有人能帮我做这件事所需的额外代码

<?php

$mysqli_connection = new MySQLi('localhost', 'root', 'secret', 'edgeserver');
if ($mysqli_connection->connect_error) {
   echo "Not connected, error: " . $mysqli_connection->connect_error;
}

$sql = "SELECT SessionLogs.sessionid, SessionLogs.eventid, BetStatus.BetStatus, EventStatus.EventStatus, SessionLogs.activestatusid
FROM SessionLogs INNER JOIN
EventStatus ON SessionLogs.eventstatusid = EventStatus.EventStatusID INNER JOIN
BetStatus ON SessionLogs.betstatusid = BetStatus.BetStatusID
where ActiveStatusID = 1
";




$res = $mysqli_connection->query($sql);

$xml = new XMLWriter();

$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);

$xml->startElement('Alive');
$xml->writeAttribute('timestamp', date('c'));

if($res === FALSE) { 
    die(mysqli_error()); // TODO: better error handling
}

while ($row = mysqli_fetch_assoc($res)) {
  $xml->startElement("Event");

  $xml->writeAttribute('sessionid', $row['sessionid']);
  $xml->writeAttribute('eventid', $row['eventid']);
  $xml->writeAttribute('BetStatus', $row['BetStatus']);
  $xml->writeAttribute('EventStatus', $row['EventStatus']);
  $xml->writeAttribute('activestatusid', $row['activestatusid']);

  $xml->endElement();
}

$xml->endElement();
$xml->endElement();

header('Content-type: text/xml');
$xml->flush();

?>
openURI(“php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('Alive');
$xml->writeAttribute('timestamp',date('c');
如果($res==FALSE){
die(mysqli_error());//TODO:更好的错误处理
}
while($row=mysqli\u fetch\u assoc($res)){
$xml->startElement(“事件”);
$xml->writeAttribute('sessionid',$row['sessionid']);
$xml->writeAttribute('eventid',$row['eventid']);
$xml->writeAttribute('BetStatus',$row['BetStatus']);
$xml->writeAttribute('EventStatus',$row['EventStatus']);
$xml->writeAttribute('activestatusid',$row['activestatusid']);
$xml->endElement();
}
$xml->endElement();
$xml->endElement();
标题('Content-type:text/xml');
$xml->flush();
?>

请帮忙。谢谢。

您可以使用curl和以下代码发送xml数据

$input_xml = ''; //XML Data 
$url=''; // URL


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POSTFIELDS,
            "xmlRequest=" . $input_xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);

使用
$xml->openMemory()
$xmlString=$xml->outputMemory()
来捕获XMLWriter对象()的缓存。

好的,感谢伟大的开始,有没有办法将上面的xml代码定义为一个变量,这样我就可以输入:$input\u xml=$xmlvariable?