我有一个简单的代码,可以抓取,然后处理给定URL中的内容,代码是这样的:
$cid = 'MCJ0001';
$asisqueryurl = "http://gw.harviz.ro:88/interfata/asisquery.ashx";
$xmlurl = $asisqueryurl . "?abonat=" . $cid . "&operatie=iaListaFacturi";
echo $xmlurl.'<br />';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $xmlurl);
$data = curl_exec($ch);
$status=curl_getinfo($ch);
if($data === false) {
echo 'Curl error: ' . curl_error($ch);
return;
} else {
var_dump($status);
$newdata=simplexml_load_string($data);
foreach($newdata as $facturi){
echo "nr factura ".$facturi['factura']."<br />";
}
}
curl_close($ch);
您可以在此处看到输出: Example1 问题是,我需要在Joomla插件中执行相同的操作。 我尝试了多种方法,从使用JHTML类加载诸如以下内容:
$http = JHttpFactory::getHttp();
$data=$http->get($xmlurl);
仅使用
之类的cURL $ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $xmlurl);
$status=curl_getinfo($ch);
$data = curl_exec($ch);
JFactory::getApplication()->enqueueMessage(
JText::_('Last status codes:'.json_encode($status)), 'error');
curl_close($ch);
if($data === false) {
JFactory::getApplication()->enqueueMessage(
JText::_('Curl error: ' . curl_error($ch)), 'error');
return;
} else {
$newdata=simplexml_load_string($data);
foreach($newdata as $facturi){
JFactory::getApplication()->enqueueMessage(
JText::_("nr factura ".$facturi['factura']), 'message');
}
return $newdata;
但是返回的结果始终为空,也不会显示任何错误。 如果有帮助,这是上面代码返回的状态代码:
Last status codes:
{"url":"http:\/\/gw.harviz.ro:88\/interfata\/asisquery.ashx?abonat=MCJ0001&operatie=iaListaFacturi",
"content_type":"text\/plain; charset=utf-8",
"http_code":200,
"header_size":220,
"request_size":121,
"filetime":-1,
"ssl_verify_result":0,
"redirect_count":0,
"total_time":0.75255700000000003146993776681483723223209381103515625,
"namelookup_time":0.454531999999999991590726722279214300215244293212890625,
"connect_time":0.6023929999999999562732000413234345614910125732421875,
"pretransfer_time":0.60243400000000002503242058082832954823970794677734375,
"size_upload":0,
"size_download":29,
"speed_download":38,
"speed_upload":0,
"download_content_length":29,
"upload_content_length":-1,
"starttransfer_time":0.7525370000000000114681597551680169999599456787109375,
"redirect_time":0,
"redirect_url":"",
"primary_ip":"89.36.160.51",
"certinfo":[],
"primary_port":88,
"local_ip":"209.59.132.190",
"local_port":41906}
任何想法都会受到赞赏,我已经在这个问题上花了几天的时间。 TIA!