为什么我在使用multi curl时没有得到响应?当发出一个post请求时,一切都按预期工作。下面的代码中是否遗漏了什么?
$urls = array(
'',
'http://example.com',
'http://example.com',
'http://example.com',
'http://example.com',
'http://example.com',
);
$url_count = count($urls);
$ch = array();
$mh = curl_multi_init();
for($i = 1; $i < $url_count; $i++) {
$url = $urls[$i];
$ch[$i] = curl_init($url);
curl_setopt_array($ch[$i], array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetItemInfoPage xmlns="http://www.example.com/">
<itemno></itemno>
<custno></custno>
<webdist></webdist>
<prodcat>005</prodcat>
<pageno>' . $i . '</pageno>
</GetItemInfoPage>
</soap:Body>
</soap:Envelope>',
CURLOPT_HTTPHEADER => array(
'Content-Type: text/xml'
),
));
curl_multi_add_handle($mh, $ch[$i]);
}
do {
$status = curl_multi_exec($mh,$running);
} while(0 < $running);
for($i = 1; $i < $url_count; $i++) {
$results[] = curl_multi_getcontent($ch[$i]);
}
var_dump($results);
以下是返回的内容:
array(5) { [0]=> string(1881375) "" [1]=> string(2751705) "" [2]=> string(3043756) "" [3]=> string(3306605) "" [4]=> string(2584404) "" }
任何帮助都将不胜感激。
1条答案
按热度按时间oiopk7p51#
如var_dump()所示,内容不是空的。
字符串太大,因此无法显示或内容可能会破坏HTML/XML混合。
如果你想在浏览器中看到它,你可以在输出前退出它。