传入请求标头在Codeigner4中为空



我使用官方shopify Php API库和Codeigner4开发一个shopify公共应用程序。我在shopify中注册了产品更新Webhook,它将响应发送到我的一个代码点火器控制器。

问题是在处理请求后,我看到空标头值如下:

{"主机":{};用户代理":{},";内容长度":{},";接受":{},";接受编码":{},";内容类型":{},";X-Forwarded-For":{},";X-Forwarded-Proto":{},";X-Shopify-Api-Version":{},";X-Shopify-Hmac-Sha256〃:{},";X-Shopify-Product-Id":{},";X-Shopify-Shop-Domain":{},";X-Shopify-Topic":{},";X-Shopify-Webhook-Id":{}}

控制器是:

class ProdHook Extends Controller{
public function index(){
$headers = $this->request->headers();
print_r($headers);
}
}

$this->trequest->headers()返回空标头值。但是,当我用原生php函数getallheaders()替换它时,我可以毫无问题地获得所有头值。getallheaders()的输出为:

{"主机":"e703.ngrok.io","用户代理":"法拉第v1.8.0","内容长度":"2132","接受":">/","接收编码":"gzip;q=1.0,deflate;q=0.6,identity;q=0.3","属性类型";:"application/json","X-Forwarded-Forf":"34.xx.xxx.11","X-Forwarded-Proto":"https"X-Shopify-Api-Version":"2021-10"X-Shopify-Hmac-Sha256〃:"xxxxxxxx"X-Shopify-Product-Id":"78803xxxxxx922"X-Shopify-Shop-Domain":"xxxxx.myshopify.com"X-Shopify-Topic":"产品/更新"X-Shopify-Webhook-Id":"uasdhxxxxx-b30c-fdc6e6865609"}

我不知道如何解决这个问题。我想坚持使用原生codeigner4。提前谢谢。

检索标头

您可以使用headers()方法,返回所有标头的数组键作为标头的名称,值是CodeIgniterHTTPHeader:

$headers = $this->request->headers();
array_walk($headers, function(&$value, $key) {
$value = $value->getValue();
});
print_r($headers);

相关内容

  • 没有找到相关文章

最新更新