我一直在写一些PHP脚本..
$gettarget = $argv[2];
echo "Trying to do something . . .\n";
sleep(2);
$ch = curl_init($gettarget); // initialize curl with given url
$useragent = "Some user agent ";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // add useragent
$response = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
echo $response;
echo "Done";
所以这就是发生了什么,它来到“尝试做某事”然后没有任何事情发生,Done没有得到回应,这意味着卷曲有问题,我真的不知道cURL是什么,所以我以为我会在这里发帖。
答案 0 :(得分:1)
您还没有在此代码块中执行curl。最后需要$response = curl_exec( $ch );
。
$gettarget = $argv[2];
echo "Trying to do something . . .\n";
sleep(2);
$ch = curl_init($gettarget); // initialize curl with given url
$useragent = "Some user agent ";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // add useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // setopt() does not exec()
// write the response to a variable
$response = curl_exec( $ch );
echo $response;
echo "Done";
答案 1 :(得分:1)
$response = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
应该是
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_setopt()
调用告诉它在您调用curl_exec()