php use not allowed,PHP Curl - Received HTTP/0.9 when not allowed

问题

I stumbled over a weird behavior when I try to send a post HTTP/2.0 request to apples push service:

$http2ch = curl_init();

curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);

curl_setopt($http2ch, CURLOPT_URL, 'https://api.push.apple.com/3/device/megauniquedevicetokendummy');

curl_setopt($http2ch, CURLOPT_PORT, 443);

curl_setopt($http2ch, CURLOPT_HTTPHEADER, $httpHeader);

curl_setopt($http2ch, CURLOPT_POST, true);

curl_setopt($http2ch, CURLOPT_POSTFIELDS, $body);

curl_setopt($http2ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($http2ch, CURLOPT_TIMEOUT, 30);

curl_setopt($http2ch, CURLOPT_HEADER, 1);

$result = curl_exec($http2ch);

if ($result === false) {

throw new \Exception("Curl failed: " . curl_error($http2ch) . " | " . curl_getinfo($http2ch, CURLINFO_HTTP_CODE));

}

The exception is thrown with the Message:

Curl failed: Received HTTP/0.9 when not allowed | 0

I explicitly told curl to use HTTP/2.0 on the second line of the code snipped above.

Does anyone have any idea what that error message means and why curl uses such an old HTTP version?

I am on PHP 7.2 and curl version 7.66.0.

回答1:

I figured it out.

Make sure that curl is compiled with nghttp2.

If you are unsure, you can check it on your terminal using curl --version

If you dont find nghttp2/{version} you need to compile curl again with nghttp2.

curl --version example where nghttp2 is missing:

curl 7.66.0 (amd64-portbld-freebsd12.0) libcurl/7.66.0 OpenSSL/1.1.1d zlib/1.2.11

curl --version example where nghttp2 is available:

curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2

来源:https://stackoverflow.com/questions/59048926/php-curl-received-http-0-9-when-not-allowed

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值