You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PHP调用Clickatell API发短信遇HTTP 405错误求助

Fixing "HTTP 405 Method Not Allowed" Error with Clickatell SMS API in PHP

Let's break down why you're hitting this error and fix it step by step:

1. What's Causing the 405 Error?

You've got two main issues here:

  • Wrong HTTP Method: You're sending a POST request, but Clickatell's traditional HTTP send endpoint expects a GET request.
  • Malformed URL: Your URL has critical formatting mistakes:
    • No ? separator between the endpoint path (send) and the first query parameter (apiKey), so it's reading sendapiKey= as part of the path instead of a parameter.
    • Using HTML-encoded & instead of plain & to separate query parameters — curl can't parse these correctly.

2. Corrected Code

Here's the fixed version with explanations:

// Fix the URL structure: add ? after send, replace & with &
$url = 'https://platform.clickatell.com/messages/http/send?apiKey=ordnzDdGdRhqdnjdf3ZmzYA==&to=904234234&content=your+password+is+BhSTV';

$ch = curl_init($url);

// Keep this to capture the response as a string instead of outputting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Disable SSL verification (note: for production, enable this with valid certificates)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// REMOVE the POST option — this API requires GET requests
// curl_setopt($ch, CURLOPT_POST, 1);

// Execute the request
$response = curl_exec($ch);

// Add error checking to catch curl-specific issues
if(curl_errno($ch)){
    echo 'Curl error: ' . curl_error($ch);
} else {
    echo $response;
}

// Clean up the curl handle
curl_close($ch);

3. Key Fixes Explained

  • URL Correction: Added ? to separate the endpoint from parameters, and swapped & for plain & so curl can read each parameter properly.
  • HTTP Method Match: Removed the CURLOPT_POST setting to use curl's default GET method, which aligns with Clickatell's API requirements.
  • Error Handling: Added curl_errno() checks to catch any unexpected curl issues that might pop up later.

Bonus Production Tip

For live environments, turn CURLOPT_SSL_VERIFYPEER back to true — disabling it skips SSL certificate validation, which is a security risk. If your server doesn't have a default CA bundle, you can specify one using CURLOPT_CAINFO.

内容的提问来源于stack exchange,提问作者Abobaker EngIt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:43:35