I have multiple XML_PAYLOAD
's to post (different xml posts for each while loop). When I run the loop it will only POST
the data of the first $i
loop. How can I get it to POST
new data for each $i
loop?
$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++;
}
define defines a constant. It means that it cannot change once it set. You should use variables like that:
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++;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.