title: Connecting to Apple's APNS using cURL with HTTP\2 support via nghttp2
body: <p>I've attempted to compile cURL with HTTP/2 support by following <a href="https://serversforhackers.com/video/curl-with-http2-support" rel="nofollow">this tutorial</a>. I'm using <a href="https://www.docker.com/" rel="nofollow">Docker</a> and my application is based off the <a href="https://hub.docker.com/_/php/" rel="nofollow">official PHP Docker image</a>, which uses Debian, although I've produced the same problems in an Ubuntu machine running inside a <a href="https://www.vagrantup.com/" rel="nofollow">Vagrant</a> VM.</p>
  
  <p>There appears to be no problem at first. Indeed, running <code>curl --version</code> shows everything I'd expect:</p>
  
  <pre><code>curl 7.47.1 (x86_64-pc-linux-gnu) libcurl/7.47.1 OpenSSL/1.0.1k zlib/1.2.8 libidn/1.29 libssh2/1.4.3 nghttp2/1.7.1 librtmp/2.3
  Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
  Features: IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 
  </code></pre>
  
  <p>Also, I can connect to <a href="https://nghttp2.org" rel="nofollow">https://nghttp2.org</a> just fine:</p>
  
  <pre><code>curl --http2 -I https://nghttp2.org
  HTTP/2.0 200
  date:Mon, 15 Feb 2016 18:02:34 GMT
  content-type:text/html
  content-length:6680
  last-modified:Thu, 11 Feb 2016 14:29:49 GMT
  etag:"56bc9add-1a18"
  link:&lt;/stylesheets/screen.css&gt;; rel=preload; as=stylesheet
  accept-ranges:bytes
  x-backend-header-rtt:0.000581
  server:nghttpx nghttp2/1.8.0-DEV
  via:1.1 nghttpx
  strict-transport-security:max-age=31536000
  x-frame-options:SAMEORIGIN
  x-xss-protection:1; mode=block
  x-content-type-options:nosniff
  </code></pre>
  
  <p>The problems begin when trying to connect to Apple's recently re-launched <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html#//apple_ref/doc/uid/TP40008194-CH101-SW1" rel="nofollow">APNS Provider API</a> which now runs on HTTP/2.</p>
  
  <p>I've installed curl via Homebrew on my Mac (using <code>--with-nghttp2</code>) and I can get the following (expected) response:</p>
  
  <pre><code>curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
  {"reason":"Forbidden"}
  </code></pre>
  
  <p>However, if I try to run the same command from within my Docker image, I get:</p>
  
  <pre><code>curl -d 'Hello' --http2 https://api.push.apple.com/3/device/test
  ?@@?HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: 504f5354202f332f6465766963652f746573742048545450
  </code></pre>
  
  <p>I'm unsure why this problems seems to be specific to Apple's service, and what needs to be done to remedy the situation.</p>
  
  <p>Any help would be <em>greatly</em> appreciated!</p>