卷曲返回空页

时间:2014-05-22 07:19:48

标签: php curl

我正在尝试卷曲http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution=640x480Quality=Standard此位置并每次都返回空页。我的代码是

  $image = 'http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution=640x480&Quality=Standard';

  $ch = curl_init();

  curl_setopt($ch,CURLOPT_VERBOSE,true);

  curl_setopt($ch, CURLOPT_URL, $image);

  $store = curl_exec ($ch);

  echo $store;
  curl_close ($ch);

有人可以告诉我缺少什么吗?

2 个答案:

答案 0 :(得分:2)

尝试做:

...
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $image);
// Get binary data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

$image = curl_exec($ch);
curl_close($ch);

// output to browser
header("Content-type: image/jpeg");
echo $image;

修改:尝试urlencode()将网址设为:

$image = 'http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution='.urlencode('640x480&Quality=Standard');

答案 1 :(得分:0)

尝试添加

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

所以代码将是: -

$image = 'http://island-alpaca.selfip.com:10202/SnapShotJPEG?Resolution=640x480&Quality=Standard';
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_VERBOSE,true); 
 curl_setopt($ch, CURLOPT_URL, $image); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
 $store = curl_exec ($ch); 
 curl_close ($ch);
 header("Content-type: image/jpeg");
 echo $store;