问题

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

php use not allowed,PHP Curl - Received HTTP/0.9 when not allowed相关推荐

  1. Invalid config event received: {version=0, server

    Invalid config event received: {version=0, server 本文没有提供解决办法,这个错误不影响使用,可以忽略 使用 zookeeper 作为 SpringCl ...

  2. php 405跳转,php采用curl访问域名返回405 method not allowed提示的解决方法

    /** * http测试 * 注:PHP版本5.2以上才支持CURL_IPRESOLVE_V4 * @param $url 网站域名 * @param $type 网站访问协议 * @param $i ...

  3. pymysql.err.InternalError: (1130, Host '127.0.0.1' is not allowed to connect to this MySQL server)

    首先采用[1]: mysql -u root -p mysql>use mysql; mysql>select 'host' from user where user='root'; my ...

  4. mysql8.0提示is not allowed to connect to this MySQL server

    出现这种情况的原因是因为: mysql数据库只允许自身所在的本机器连接,不允许远程连接. 解决: 在mysql所在服务器上面登录进mysql数据库中: use mysql;   select host ...

  5. 【BATJ面试必会】Java 基础篇

    <!-- GFM-TOC --> 一.数据类型 包装类型 缓存池 二.String 概览 不可变的好处 String, StringBuffer and StringBuilder Str ...

  6. java构造函数重载继承_Java基础-继承 - 写代码换盆的个人空间 - OSCHINA - 中文开源技术交流社区...

    访问权限 Java 中有三个访问权限修饰符:private.protected 以及 public,如果不加访问修饰符,表示包级可见. 可以对类或类中的成员(字段和方法)加上访问修饰符. 类可见表示其 ...

  7. Java深入浅出讲解

    一.数据类型 基本类型 byte/8 char/16 short/16 int/32 float/32 long/64 double/64 boolean/~ boolean 只有两个值:true.f ...

  8. TSLint 配置规则

    TSLint core rules 原文:https://palantir.github.io/tslint/rules/ Lint rules encode logic for syntactic ...

  9. Java基础——夯实基础

    基础(基本) 特性 Java 各版本的新特性 New highlights in Java SE 8 Lambda Expressions Pipelines and Streams Date and ...

  10. Java实习生面试题整理

    一.数据类型 包装类型 八个基本类型: boolean/1 byte/8 char/16 short/16 int/32 float/32 long/64 double/64 基本类型都有对应的包装类 ...

最新文章

  1. 全球最大规模学术不端调查显示,53%的博士生会从事有问题的研究
  2. 【云周刊】第208期:阿里云MWC 2019发布7款重磅产品,助力全球企业迈向智能化...
  3. ASP.NET MVC5+EF6+EasyUI 后台管理系统(47)-工作流设计-补充
  4. stl-----全排列
  5. linux ssh服务的优化,SSH服务端配置、优化加速、安全防护
  6. JUC系列(十) | ForkJoin框架 并行处理任务
  7. JQuery-Table斑马线
  8. boost::mp11::mp_not_fn相关用法的测试程序
  9. 东拉西扯:那些“老”互联网公司
  10. 2017 ACM Jordanian Collegiate J.Efficiency Test 动态规划、类倍增
  11. 登录微信用android设备,Android 之微信登录
  12. unity, 判断可见性
  13. 刷机-升级到3.90M33-3的方法
  14. EVIEWS 学习基本操作+数据输入 01
  15. Vue学习(学习打卡Day13)
  16. 强化学习实战-使用Sarsa算法解决悬崖问题
  17. pcl_viewer的使用
  18. HTML5结构元素总结
  19. 2021年第四届“传智杯“大学B组
  20. 利用Arcpy批量图斑生成图片

热门文章

  1. java中try-catch-finally的使用
  2. web开发设为首页、添加到收藏夹实现方法
  3. 计算机三种桌面图标,例举win7电脑桌面图标排列方式
  4. cdr 表格自动填充文字_CDR插件表格安装教程
  5. html5中正则表达式怎么加,HTML5中的字母正则表达式(Alphabetic Regex in HTML5)
  6. 元宇宙与泛娱乐的邂逅:次世代第一CP养成记
  7. 中元节,会吃的民族带你了解“鬼节”的习俗
  8. Cross-Lingual NER Using Parallel Corpus: A New Approach Using XLM-RoBERTa Alignment
  9. 服务器维护以后多久刷潮汐护符,魔兽世界怀旧服潮汐护符怎么获得
  10. java遍历二级城市_java8用Lambda遍历省市区三级数据