為什么我在使用 multi curl 時沒有得到回應?發出單個發布請求時,一切都按預期作業。下面的代碼中是否缺少我的東西?
$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) "" }
任何幫助將不勝感激。
uj5u.com熱心網友回復:
正如您的 var_dump() 所示,內容不為空。
array(5) { [0]=> string(1881375) "" [1]=> string(2751705) "" [2]=> string(3043756) "" [3]=> string(3306605) "" [4]=> string(2584404) "" }
字串太大,因此無法顯示,否則內容可能會破壞 HTML/XML 混合。
如果您想在瀏覽器中查看它,您可以在輸出之前對其進行轉義。
echo htmlentities($results[0]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/505190.html
下一篇:使用cURL的多行GET請求
