【发布时间】:2015-07-27 15:11:32
【问题描述】:
我有一个包含 curl 代码的 php 文件,以便访问 api。但是当我在服务器上上传这个文件并尝试通过 url 执行它时,没有显示输出。也不显示文件符号,因为它显示为 php 文件。指导我如何解决这个问题。 php文件中的代码是:
<?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); ?>
我的服务器索引如图所示。据我了解,php 文件符号与我上传的图像中显示的不同。任何人都可以对此提出建议,如果它可以帮助我解决我的目标。
【问题讨论】:
-
在 curl_exec 之后,检查 curl_error
-
POSTFIELDS应该是 url 编码的字符串或数组,我在您的代码中看不到任何<?php登录。 -
我添加 curl_exec 仍然文件没有执行。
-
@NeelIon 请解释 POSTFIELDS 应该是 url 编码的字符串还是数组?我错误地忘记在上面的问题代码中添加
-
您可以使用
key1=value1&key2=value2这种格式发送post参数。