PHP cURL调用在Ubuntu 14.05中使用PHP 5.5.9,但在使用PHP 5.3的Ubuntu 12.04上不起作用

时间:2016-09-02 20:17:43

标签: php ubuntu curl

我在生产服务器(Ubuntu 12.04,PHP 5.3)中使用php调用cURL时遇到问题。

它适用于我的localhost(Ubuntu 14.04,PHP 5.5.9)

这是进行cURL调用的函数。

public function callSendGrid($url,$method,$request_body = null)
{ 

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, ["authorization: Bearer ".$this->sendGridApiKey]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    if($request_body)
        curl_setopt($ch, CURLOPT_POSTFIELDS,$request_body);

    switch($method){
        case 'PUT':
        case 'DELETE':
        case 'PATCH':
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        break;
        case 'POST':
            curl_setopt($ch, CURLOPT_POST, 1);
        break;
        case 'GET':
            curl_setopt($ch, CURLOPT_HTTPGET, 1);
        break;
    }

    $response = json_decode(curl_exec($ch));
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    return ['status' => $http_status,'response' => $response];
}

我称之为

$this->Model->callSendGrid('https://api.sendgrid.com/v3/campaigns/123123/schedules/now', 'POST');

它适用于我的本地环境,但不适用于我的生产环境。

在我的本地环境中,它会返回

['status' => 201, 'response' => *a json decoded response*]

在我的生产环境中,它会返回

['status' => 400, 'response' => *absolutely nothing here*]

值得一提的是其他一些电话有效;

此调用适用于两种环境:

$this->Model->callSendGrid('https://api.sendgrid.com/v3/campaigns/', 'POST', 'a json that the api accepts');

我只是看不出两个电话之间有任何区别,只是第一个没有发布数据。但它不应该在一个环境中失败而在另一个环境中工作。

我正在更新我的生产环境以匹配我的本地环境,但我没有看到使用PHP 5.3的cURL中的任何问题;

我希望你们能帮助我。在我的本地环境中查看完全相同的调用工作并且不在我的生产环境中工作非常奇怪,而其他调用适用于这两种环境。它不是我打电话的API的问题,因为它适用于本地。我已经在没有json_decode的情况下抛弃了curl_response,它在生产环境中返回了一个BAD REQUEST。

我真的在这里变得疯狂。

由于

0 个答案:

没有答案