试图用PHP CURL获取URL的连接,但没有成功


Trying to get connects of URL with PHP CURL , but no success

这是我的URL:https://webservices-dev.compuscan.co.za:9443/PersonStatusService/user2/password2/8310240031083/XML

我正在尝试用PHP curl获取它的内容,但没有成功,希望有人能帮忙。

这是我的代码:

// you can add anoother curl options too
// see here - http://php.net/manual/en/function.curl-setopt.php 
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_POST, TRUE);             // Use POST method
//curl_setopt($ch, CURLOPT_POSTFIELDS, "var1=1&var2=2&var3=3");  // Define POST values
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
$output = curl_getinfo($ch);
print_r($output);
curl_close($ch);
return $data;
}
$url = "https://webservices-dev.compuscan.co.za:9443/PersonStatusService/user2/password2/8310240031083/XML" ;

$variablee = get_data($url);
echo $variable;

我得到了预期的结果。

应该是

$variablee = get_data($url);
echo $variablee; //<--- Must be $variablee (as you have defined it above)

输出:

数组([url]=>https://webservices-dev.compuscan.co.za:9443/PersonStatusService/user2/password2/8310240031083/XML[content_type]=>text/plain;charset=utf-8[http_code]=>200[header_size]=>81[requestrongize]=>192[filetime]=>-1[ssl_verify_result]=>19[redirect_count]=>0[total_time]=>1.544[namelookup_time]=>0[connect_time]->0.343[protransfer_time]>>1.186[size_upload]=>0[size_download]=>656[speed_download]=>424[speed_upload]=>0[download_content_length]=>656[upload_content_length]=>0[starttransfer_time]=>1.544[redirect_time]=>0[certinfo]=>数组()[primary_ip]=>196.34.30.23[primary_port]=>9443[local_ip]=>192.168.72.37[local_port]=>61090[redirect_url]=>)8310240031083索赔通知1983/10/24财年2012/03/242013/09/308STWEST ACRES ext1312012013/08/130768333118

function get_data($url) {
$ch = curl_init($url);
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; 
Windows NT 6.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 404) {
curl_close($ch);
return '404';
} else {
curl_close($ch);
return $data;
}
}

这个功能对我来说非常有用,也许有人觉得它和我一样有用。我不是假装回答你的问题(好吧,我迟到了9个月),而是解决人们对类似问题的类似问题。