在PHP提交时从URL发送XML

在PHP提交时从URL发送XML,php,xml,curl,xml-parsing,Php,Xml,Curl,Xml Parsing,让我们设想以下情况: 您有一个带有html表单的简单php页面,允许用户输入以下数据: 电话号码 短信 例如: <form action="xml-file.xml" method="get"> <input type="text" id="to" name="to" value="" /> <input type="text" id="text" name="text" value="" /> <input type="submi

让我们设想以下情况:

您有一个带有html表单的简单php页面,允许用户输入以下数据:

  • 电话号码
  • 短信
例如:

<form action="xml-file.xml" method="get">
   <input type="text" id="to" name="to" value="" />
   <input type="text" id="text" name="text" value="" />
   <input type="submit" />
</form>

谢谢

将XML作为字符串返回并发布

...
$xml_post_string = 'XML='.urlencode($xml->asXML());  

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://theurl.com');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);
curl_close($ch);
...

谢谢你的回答。该
$xml\u post\u字符串
是否会从先前保存的
asXML('sms.xml')
返回保存的值?另外,
CURLOPT_URL
是否直接接受URL上的端口号?而且,该
urlencode
会将生成的XML编码到
“内容类型”、“应用程序/x-www-form-urlencoded”
<?php
  $xml = simplexml_load_file("sms.xml");          // Load XML file
  $xml->Title3 = $_GET['to'];                         // Updating <Title3> from GET method
  $xml->Title5[0]->Title51Content = $_GET['text'];      // Updating <Title51> from GET method
  $xml->asXML('sms.xml');                         // Saving the XML file
?>
<?xml version="1.0" encoding="UTF-8"?>
<Title1>
   <Title2>Some Text</Title2>
   <Title3>Variable 1</Title3>
   <Title4>Some Text</Title4>
   <Title5>
      <Title51>Variable 2</Title51>
   </Title5>
</Title1>
XML=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3...
...
$xml_post_string = 'XML='.urlencode($xml->asXML());  

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://theurl.com');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);
curl_close($ch);
...