PHP CURL POST方法给出500个响应代码

时间:2018-12-04 15:05:54

标签: php curl post http-status-code-500

嗨,我知道那里已经有类似的问题,但是我已经排除了它们。

所以我试图用curl制作一个简单的POST方法,并不断出现错误500。我错过了什么吗?

// Get cURL resource
$curl = curl_init();

//POST request body
$post_data = array(
    'subscription_uuid' => $subscription_uuid,
    'merchant' => $merchant_id
);

echo "JSON in POSTFIELDS:" . json_encode($post_data, JSON_PRETTY_PRINT) . "\n";

// Set Headers, endpoint and option to output response as string
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://subscriptions-jwt.fortumo.io/subscriptions/cancel',
    CURLOPT_POST => 1,
    CURLOPT_HTTPHEADER => array(
        'Content Type: application/json' ,
        'Authorization: Bearer' . " " . $jwt

    ),
    CURLOPT_POSTFIELDS => json_encode($post_data)
));

// Send the request & save response
$unsubscribe_response = curl_exec($curl);

$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

//Request URL:
echo "Unsubscribe Request URL:\n" . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . "\n";
echo "Error Code:" . $statusCode . "\n";

这是我从该代码块得到的响应(使用echo-s对此进行了简化):

JSON in POSTFIELDS:{
    "subscription_uuid": "<<MY-TOKEN>>",
    "merchant": "<<MY-TOKEN>>"
}
Unsubscribe Request URL:
https://subscriptions-jwt.fortumo.io/subscriptions/cancel
Error Code:500

更奇怪的是,在高级REST客户端等工具中使用完全相同的标头,JSON邮戳字段和URL集,一切正常,我得到200响应,没有问题。

我的代码有问题。有人可以发现问题吗?预先感谢!

0 个答案:

没有答案