PHP 的 simplexml 可以在请求中包含 POST 数据吗?



我正在加载一个带有 PHP 的 simplexml 的 xml 文件,并在 URL 中带有 GET 变量。

$xml = simplexml_load_file("http://localhost/service.xml?item=1")

是否可以将item=1作为 POST 变量而不是 GET 传递?

如有必要,我可以使用 simplexml 以外的其他东西。

您可以使用curl获取数据,然后使用simplexml_load_string加载

// Inıt curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/service.xml");
curl_setopt($ch, CURLOPT_POST, 1);
// Set post fields
curl_setopt($ch, CURLOPT_POSTFIELDS, "item=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// get output
$output = curl_exec($ch);
// Close curl
curl_close ($ch);
// simplexml_load_string
$xml = simplexml_load_string($output);

最新更新