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

报告相同问题?