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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?