dskzap8756 2016-04-29 09:34
浏览 94
已采纳

Github webhook PHP脚本返回“缺少HTTP'内容类型'标题。”

Some information beforehand:

I have 1 servers with 2 domains, one is the live version (live), the other is for testing purposes (redesign). I'm using GitHub webhooks to automatically update my redesign server with the repository so that when there's multiple people working on the repo, we don't have to manually deploy it every time.

Now, I have found a PHP script (This is exactly how I use it apart from the secret) on GitHub in which the webhook is being parsed returns an error saying that the Content-Type header is missing, while when I look in the webhook delivery it clearly has the header.

Header present.

The error presents itself on line 33 of the PHP script which checks if the HTTP_CONTENT_TYPE is present by checking

if (!isset($_SERVER['HTTP_CONTENT_TYPE'])) {
    throw new \Exception("Missing HTTP 'Content-Type' header.");
} 

To ask an actual question: How can the PHP if throw the exception when the header is clearly present?

  • 写回答

1条回答 默认 最新

  • douba8819 2016-04-29 10:02
    关注

    I think the name HTTP_CONTENT_TYPE is wrong. It looks like it has been used as a fix for the bug Sets HTTP_CONTENT_TYPE but not CONTENT_TYPE.

    Normally CONTENT_TYPE property should be used following the RFC 3875

    I made a simple test to check how it works

    1. Created an index.php file on my web server

      echo $_SERVER['CONTENT_TYPE'].PHP_EOL;

    2. Opened the file using cUrl

      $ curl -H "Content-Type: application/json" http://localhost

    The outpus for me is

    application/json

    1. HTTP_CONTENT_TYPE property is not set in my test case.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示