Unexpected HTTP/1.x request: POST /3/device/XXXX

前端 未结 4 522
北荒
北荒 2021-01-12 05:05

Hi i am sending IOS push notifications using apns and curl in php and getting this error message.

I also define \'CURL_HTTP_VERSION_2_0\' but still getting this erro

相关标签:
4条回答
  • 2021-01-12 05:08

    Problem:

    For me this was because OpenSSL and nghttp2 were missing from curl and/or my server. I also believe an older version of PHP (less than 7.0) could also cause this issue.

    You can check if curl is using OpenSSL and nghttp2 using the following terminal command on your server:

    curl -V
    

    If the output does not mention OpenSSL and nghttp2 then this is why you are seeing the HTTP/1.x error.

    I was using the AWS EC2 instance 'Amazon Linux 2 AMI'. I could not find a way to install OpenSSL or nghttp2 so I had to create a new server, see below.

    Solution:

    I had to create a new AWS EC2 instance of 'Amazon Linux AMI 2018.03.0 (HVM)'.

    Note: Do not create instance of 'Amazon Linux 2 AMI (HVM)' as you will end up with the original issue.

    I then followed this to install PHP7 on the new server: How to install PHP 7 on EC2 t2.micro Instance running Amazon Linux Distro

    I then checked curl version, OpenSSL and nghttp2 were both present:

    curl -V
    

    I then put all the code and resources onto the new server and it worked!

    Note: The actual PHP code I used to create the notification can be found here: Send iOS Push notification in php with .p8 file

    0 讨论(0)
  • 2021-01-12 05:21

    I was using an older version of PHP where phpinfo() showed that HTTP2 wasn't enabled for the curl library. Upgrading PHP to a more recent version fixed this issue for me.

    0 讨论(0)
  • 2021-01-12 05:24

    Kindly enable your http2 in curl package of your php.

    Also see the phpinfo() if you have already enabled the http2 support for curl or not.

    After that just set your CURLOPT_HTTP_VERSION curl option with 3

    0 讨论(0)
  • 2021-01-12 05:27

    I was getting the same Unexpected HTTP/1.x request: POST /3/device/XXXX response when using cURL in PHP but never when using curl on the command line.

    Simply restarting the apache webserver with sudo apachectl restart fixed the problem.

    0 讨论(0)
提交回复
热议问题