curl获取图片,同样的代码为什么一个成功,一个不成功

WBOY
Release: 2016-06-23 13:29:45
Original
1338 people have browsed it

代码一,可以显示出图片

<?phpheader('content-type:image/jpg;');//图片url一$login_url   = 'http://www.1769pt.com/include/getcode.php';$ch          = curl_init($login_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$contents = curl_exec($ch);curl_close($ch);echo $contents ;  ?>
Copy after login

代码二,无法显示图片
<?phpheader('content-type:image/jpg;');//图片url二$login_url   = 'http://172.16.28.1/root/ef30d3ea-e0c5-448e-8678-c30daccadd20/USER_CACHE/54/66/546686fc-152a-449a-8ae1-7bec1d438fc6/3.jpg';$ch = curl_init($login_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$contents = curl_exec($ch);curl_close($ch);echo $contents ; ?>
Copy after login


回复讨论(解决方案)

代码2 url无法访问

http://www.1769pt.com/include/getcode.php 是公网 url,自然应该可以访问
http://172.16.28.1/root/ef30d3ea-e0c5-448e-8678-c30daccadd20/USER_CACHE/54/66/546686fc-152a-449a-8ae1-7bec1d438fc6/3.jpg 是局域网 url,能不能访问就难说了

代码2的url直接访问失败

$error=curl_error($ch);
echo $error;

看看有什么错误。

我已经修改代码二图片地址,还是不能显示

<?phpheader('content-type:image/jpg;');//图片url二$login_url   = 'http://17wo.cn/captcha.do';$ch = curl_init($login_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$contents = curl_exec($ch);curl_close($ch);echo $contents ; ?>
Copy after login

访问直接访问就是这个

解决问题了,我在一个在线网站测试他提示“HTTP Status 400 - HTTP method POST is not supported by this URL”
然后我把//curl_setopt($ch, CURLOPT_POST, 1);这句注释掉就可以,谢谢各位

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template