【问题标题】:PhoneGap API Curl from Command Line to phpPhoneGap API Curl 从命令行到 php
【发布时间】:2012-08-29 05:23:40
【问题描述】:

我想使用https://build.phonegap.com/docs/api 上的 API 构建 phonegap 应用程序

它需要运行以下 curl 命令,该命令将返回一个令牌。

$ curl -u andrew.lunny@nitobi.com -X POST "" https://build.phonegap.com/token

这个 curl 语句在命令行上为我工作。我想在 php 中使用它。我尝试了下面给出的 php 代码,但它不起作用。

$username = "USERNAME@gmail.com";
$password = "PASSWORD";
$target_url = "https://build.phonegap.com/token"

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$result = curl_exec($ch);
curl_close ($ch);
echo $result;

【问题讨论】:

    标签: php cordova curl command-line


    【解决方案1】:

    你也可以试试shell_exec()函数:

    $cmd = "curl -u andrew.lunny@nitobi.com -X POST "" https://build.phonegap.com/token";
    $out = shell_exec($cmd);
    $data = json_decode($out);
    

    【讨论】:

      【解决方案2】:

      我找到了解决办法。

      我的本​​地主机设置有问题。当我将代码上传到网络服务器时,它就开始工作了。

      【讨论】:

        猜你喜欢
        • 2013-04-18
        • 2017-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-25
        • 1970-01-01
        相关资源
        最近更新 更多