求教curl和file_get_contents取不到数据问题

WBOY
Release: 2016-06-20 12:27:09
Original
1226 people have browsed it

Linux定时任务定时请求一个php文件,在该文件中请求java接口获取数据,但是无论是用curl还是file_get_contents返回结果都为空,求教各位大神了,谢谢!


回复讨论(解决方案)

直接访问这个PHP文件呢?

直接访问这个PHP文件呢?

用浏览器直接请求文件是有数据返回的

是否需要登录?是否需要user-agent等信息?

您隐瞒了最大的事实:目标 url

是不是定制任务设置有问题,如果php都可以访问,为什么加上计划任务就不行呢?难道是权限的问题?

    public function http($url)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HEADER, false);
        $output = curl_exec($ch);//输出内容
        curl_close($ch);
        return array($output);
    }

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!