0

我有多个XML_PAYLOAD要发布(每个 while 循环的不同 xml 帖子)。当我运行循环时,它只会POST显示第一个$i循环的数据。如何获取POST每个$i循环的新数据?

$i = 0;
while ($i < $num) {

...data

define("XML_PAYLOAD", "<?xml stuff and tags?>");
define("XML_POST_URL", "http://theurl");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);

$result = curl_exec($ch);
curl_close($ch);

$i++;
}
4

1 回答 1

1

define定义一个常量。这意味着它一旦设置就无法更改。你应该使用这样的变量:

define("XML_POST_URL", "http://theurl");
$i = 0;
while ($i < $num) {

...data

$xml_payload = "<?xml stuff and tags?>";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);

$result = curl_exec($ch);
curl_close($ch);

$i++;
}
于 2013-04-05T19:05:20.493 回答