我有volusion存储URL,我使用这个URL和curl函数连接到volusion存储。以下是我要连接的代码-
$URL ='http://v970032.y5pgm9yfhypo.demo17.volusion.com/net/WebService.aspx?Login=rashmi@edreamz.in&EncryptedPassword=24EA69124482A486AF3E6BA68DDEECBB7CBC3661EA792E0DC4A40CD6FC031E6E&Import=Update';$ch = curl_init($URL);
我只想检查给定URL的连接是否连接。我怎样才能做到这一点,请告诉我。现在如果我用-
回波$ch
它只显示资源id #2
提前谢谢。
发布于 2012-03-26 06:45:32
首先,curl_init是不够的。您需要使用curl_exec来实际发送请求。发送请求后,可以使用curl_errno检查是否返回错误,使用curl_getinfo获取有关请求和响应的更多信息,如HTTP代码(例如: 200、404)、连接时间等。
从curl_getinfo documentation: 修改的示例
<?php
// Create a curl handle
$ch = curl_init('http://v970032.y5pgm9yfhypo.demo17.volusion.com/net/WebService.aspx?Login=rashmi@edreamz.in&EncryptedPassword=24EA69124482A486AF3E6BA68DDEECBB7CBC3661EA792E0DC4A40CD6FC031E6E&Import=Update');
// Tell cURL to return the transfer instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute
$result = curl_exec($ch);
// Check if any error occured
if (!curl_errno($ch)) {
// Here, I'm outputting the value of $result but you can do whatever you'd like
// with it such as using a DOMDocument to parse XML or HTML, json_decode to
// parse JSON, etc.
echo $result;
} else {
echo 'Sorry, an error occurred while connecting to Volusion.';
}
// Close handle
curl_close($ch);根据您想要做的事情,您可能想看看curl_setopt,更具体地说,看看CURLOPT_RETURNTRANSFER和其他一些可以传递给cURL的基本选项。这些选择都有很好的记录。
https://stackoverflow.com/questions/9867702
复制相似问题