php文件与CURL命令不工作在服务器上 [英] php file with CURL commands not working on Server

查看:204
本文介绍了php文件与CURL命令不工作在服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有php文件,它包含curl代码,以便访问api。但是,当我上传这个文件在服务器上,并尝试通过url执行没有输出显示。也不显示文件符号,因为它显示为php文件。指导我如何解决这个问题。 php文件中的代码是:

I have php file which consist of curl code so as to access an api. But when I upload this file on server and try to execute it via url no output is shown. Also file symbol is not shown as it is shown for php file. Guide me how to solve this problem. The code in php file is :

 <?php   // set up the curl resource

    $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

    curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS,"{}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, 'http://184.73.165.170:3000/api/3ace632b194e4366b821f7775b51cc4e/get-ibeacon-contents'); // execute the request

    $output = curl_exec($ch);

    // output the profile information - includes the header

    //echo "curl response is :".($output). PHP_EOL; print($output);

    // close curl resource to free up system resources

    curl_close($ch); ?>

< a>

我的服务器索引如图所示。根据我的理解,一个php文件符号是不同于它在我上传的图像显示。

My server index shows as shown in image. As per my understanding a php file symbol is different than what it is shown in image I uploaded. Can anyone suggest about this ,if it helps me resolve my aim.

推荐答案

尝试以这种方式使用您的代码

Try using your code this way

     <?php

        $json=json_encode(array('key1'=>'val1','key2'=>'val2'));

        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, 'http://184.73.165.170:3000/api/3ace632b194e4366b821f7775b51cc4e/get-ibeacon-contents');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLOPT_POST, true); 
        curl_setopt($ch,CURLOPT_POSTFIELDS,$json); 


        $output = curl_exec($ch);

        var_dump(curl_getinfo($ch));
        echo curl_errno($ch) . '-' . curl_error($ch);

        curl_close($ch); 

    ?>

这篇关于php文件与CURL命令不工作在服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆