php curl post不工作

php curl post不工作,php,curl,http-post,Php,Curl,Http Post,我的POST-curl可以从命令行工作,但不能从php工作。它只是不发送PHP中的POST数据。我已经检查过它是否重写为GET,它也没有这样做,尽管如果我使用GET,GET可以工作 命令行: curl -d "something=true" file.php php: 请参阅: 不要自己设置内容长度,而是允许libcurl自己设置,以降低出错的风险 然后,您添加了两个不带冒号的标题,改为使用“=”,这可能会混淆接收端。请参阅如何使用curl发送post数据: function api_send

我的POST-curl可以从命令行工作,但不能从php工作。它只是不发送PHP中的POST数据。我已经检查过它是否重写为GET,它也没有这样做,尽管如果我使用GET,GET可以工作

命令行:

curl -d "something=true" file.php
php:

请参阅:
不要自己设置内容长度,而是允许libcurl自己设置,以降低出错的风险


然后,您添加了两个不带冒号的标题,改为使用“=”,这可能会混淆接收端。

请参阅如何使用curl发送post数据:

function api_send($params,$token,$backup = false)
{       
    static $content;
    if ($backup == true) {
        $url = 'http://app.x/api.php';
    } else {
        $url = 'http://app.x/api.php';
    }
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, $params);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    // Headers here    
    curl_setopt($c, CURLOPT_HTTPHEADER, array(
        "Authorization: Bearer $token"
    ));
    // Disable ssl check
    // curl_setopt($c, CURLOPT_SSL_VERIFYPEER => false);
    // curl_setopt($c, CURLOPT_SSL_VERIFYHOST => false);
    // Ssl version
    // curl_setopt($c, CURLOPT_SSLVERSION => 3);

    $content = curl_exec($c);
    $http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
    if ($http_status != 200 && $backup == false) {        
        api_send($params, $token, true);
    }
    curl_close($c);
    return $content;
}
以身作则

$params = array(
    'pass' => 'pass',
    'message' => 'Message here',
    'cmd' => 'sendnow'   
);
// Send data
echo api_send($params,'Token_here');

你需要试试

你有错误吗?它以什么方式不工作?php没有错误。我检查了/var/logs,但不知道要检查哪个日志:我发现每当我的curlopt_httpheader数组中有项目时,post就会显示为空。当数组为空时,我的帖子可以工作。古怪的有什么想法吗?可能是重复的
$params = array(
    'pass' => 'pass',
    'message' => 'Message here',
    'cmd' => 'sendnow'   
);
// Send data
echo api_send($params,'Token_here');