如何发送一个PHP HTTP / 2 POST请求 [英] How do I send a HTTP/2 POST request in PHP

查看:3694
本文介绍了如何发送一个PHP HTTP / 2 POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在如何一个类似的问题做我送红宝石一个HTTP / 2 POST请求
但我想我的更新与PHP服务器

I found a similar question at How do I send a HTTP/2 POST request in ruby But I want to update my server with PHP

新的苹果推送通知HTTP / 2基于这里描述API:<一href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html\" rel=\"nofollow\">https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html

The new Apple push notification HTTP/2 based API described here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html

任何使用HTTP / 2的经验帮助我做出请求在PHP客户端。

Anyone with HTTP/2 experience help me with making a request as a client in PHP.

推荐答案

curl扩展为PHP> = 5.5.24对HTTP / 2的支持。 (因为这次提交

The CURL extension for PHP >= 5.5.24 has support for HTTP/2. (since this commit)

您还需要安装的libcurl - 与HTTP / 2支持启用 - 即卷曲功能使用底层库。这意味着一个比libcurl的新7.38.0但实际上,在新越好。 libcurl的有已建成使用HTTP / 2支持显式启用,使用 - 与-nghttp2 标记在编译时

You also need a libcurl installed — the underlying library that the curl functions use — with HTTP/2 support enabled. That means a libcurl newer than 7.38.0 but really, the newer the better. Libcurl has to have been built with HTTP/2 support explicitly enabled, using the --with-nghttp2 flag at compile time.

只要使用卷曲如你正常使用,并设置 CURLOPT_HTTP_VERSION 选项在 CURL_HTTP_VERSION_2_0 使用HTTP / 2。然后你会得到升级到2.0版本要求的如果的客户端和服务器都支持它。

Just use curl as you'd normally use it, and set the CURLOPT_HTTP_VERSION option to use HTTP/2 by passing in CURL_HTTP_VERSION_2_0. Then you'll get the request upgraded to version 2 if the client and server both support it.

在此之前PHP 5.5.24,如果libcurl的已建成HTTP / 2的支持,你可以通过在 CURL_HTTP_VERSION_2_0 明确为PHP仍然会通过它的int值通过对libcurl的。目前,它的 3 价值 - 这应该不会改变,但是的可能

Prior to PHP 5.5.24, if libcurl has been built with HTTP/2 support, you can pass in the int value of CURL_HTTP_VERSION_2_0 explicitly as PHP will still pass it through to libcurl. Currently, it has a value of 3 — this should not change, but could.

if (!defined('CURL_HTTP_VERSION_2_0')) {
    define('CURL_HTTP_VERSION_2_0', 3);
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);

这篇关于如何发送一个PHP HTTP / 2 POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆