我正在加载一个带有 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);