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

前端 未结 4 651
北荒
北荒 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

提交回复
热议问题