How to force CURL to ask for http/1.1? Or maybe there's another issue, not sure

How to force CURL to ask for http/1.1? Or maybe there's another issue, not sure

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving the "HTTP Version Not Supported" Error in PHP CURL

When migrating HTTP clients from a high-level framework like Yii2 to native PHP code, you often encounter subtle protocol mismatches that standard debugging doesn't immediately reveal. A common scenario involves moving a working curl request from a framework using yii2/httpclient to a custom implementation. In your specific case, the original code successfully negotiates ALPN (Application-Layer Protocol Negotiation) and establishes an HTTP/1.1 connection, while your manual implementation receives a 505 HTTP Version Not Supported error.

The root cause lies in how modern HTTPS endpoints negotiate protocol versions during the TLS handshake. When you connect via HTTPS, the server expects to know which version of HTTP you intend to use before it finalizes the SSL session. The verbose output from your working code shows the critical line: ALPN, offering http/1.1. This indicates that the client successfully sent a hint during the TLS handshake specifying its preference for HTTP/1.1 over HTTP/2 (or other protocols).

Your custom implementation fails because it defaults to a behavior where ALPN negotiation might not be explicitly enabled or offered in the way the server requires. While CURLOPT_HTTP_VERSION controls the version of the HTTP request sent after the TLS connection is established, it does not control the protocol hint sent during the initial SSL handshake. The error you are seeing—Error 505: HTTP Version Not Supported—is a direct response from the server indicating it received an HTTP/1.0 (or similar) frame where it was expecting a specific protocol alignment or simply that the ALPN hint was missing, causing it to default to a mode that rejects your request.

You correctly identified that setting CURLOPT_HTTP_VERSION alone is insufficient if the underlying TLS library isn't configured to advertise support for HTTP/1.1 via ALPN. The command-line example you provided using --no-alpn actually worked, which is counter-intuitive but highlights a specific quirk: sometimes explicitly disabling ALPN allows the server to fall back to a strict HTTP mode that accepts your request, whereas enabling it (or leaving it as default) causes the library to attempt a negotiation that the server interprets as incompatible.

To fix this in your PHP code without relying on framework-specific dependencies, you need to ensure the SSL context is configured to allow ALPN and explicitly offer HTTP/1.1. The option CURLOPT_SSL_ENABLE_ALPN was deprecated long ago and is not available in standard builds of libcurl (it was removed in version 7.63.0). Since you are running PHP 5.6 with CURL 7.51.0, this option should theoretically be available, but its presence depends on the build flags of your specific libcurl library.

The most robust solution is to explicitly set the SSL protocol version and ensure ALPN is active by managing the SSL context options before initializing the handle or using CURLOPT_SSL_OPTIONS if available in your environment. However, the most reliable workaround for this specific "HTTP Version Not Supported" error when ALPN behavior is unpredictable is to force the use of HTTP/1.0 at the transport level or ensure that the SSL context is built with the correct features enabled.

In practice, you can often resolve this by ensuring the SSL context options are set before the connection is made. If you cannot manipulate the context directly, try disabling ALPN explicitly if your libcurl supports it via CURLOPT_SSL_OPTIONS with SSL_OP_NO_ALPN_IN_TLS, or simply rely on the default behavior which often works if the system OpenSSL library is correctly configured.

Here is a refined approach that mirrors the command-line success by ensuring the protocol version is strictly handled:

$ch = curl_init();

// Force HTTP/1.0 to avoid ALPN negotiation issues if the server is strict about it
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 

// If you specifically need HTTP/1.1 but ALPN is causing issues, 
// ensure SSL options are set correctly before exec
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'post-data-here');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://android.clients.google.com/auth');

// Only set headers if not using curl_init with POST directly for data
// curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]); 

curl_setopt($ch, CURLOPT_VERBOSE, true);
$content = curl_exec($ch);

The key takeaway is that CURLOPT_HTTP_VERSION does not control the TLS handshake protocol hint. If your server relies on ALPN to distinguish between HTTP versions and your client fails to advertise it correctly, you get a 505 error. The command-line tool's success with --no-alpn suggests that explicit negotiation is the culprit. By forcing CURL_HTTP_VERSION_1_0, you bypass the need for complex ALPN negotiation in many legacy or strict server configurations, restoring compatibility without requiring framework-specific helpers.

Our network