简体   繁体   English

如何使用PHP使用GitHub获取Web钩子数据

[英]How to get web hook data with GitHub using PHP

I've setup a GitHub webhook with a secret and selected application/x-www-form-urlencoded for the content type. 我已经为内容类型设置了一个带有秘密和选定应用程序/ x-www-form-urlencoded的GitHub webhook。

I tried to search around but there does not seem to be much info on how to use the post data, such as what does GitHub include in the POST request, can I just do: 我试图搜索一下,但似乎没有太多关于如何使用帖子数据的信息,例如GitHub在POST请求中包含的内容,我可以这样做:

$_POST["secret"] or is there more to it than that? $_POST["secret"]或者还有更多吗? I know I could test this myself but with the way I setup the webhook its hard to see the output and more of a pain to do a var_dump() for POST. 我知道我可以自己测试一下,但是我设置webhook的方式很难看到输出,而且更多的是为POST做var_dump()。

So basically my question is what is the POST layout when GitHub sends a POST request, because I am looking to validate which branch was pushed and validate the secret as well. 所以基本上我的问题是当GitHub发送POST请求时POST布局是什么,因为我希望验证哪个分支被推送并验证了秘密。

seems it is translated by PHP as $_SERVER['HTTP_X_HUB_SIGNATURE'] 似乎它被PHP翻译为$_SERVER['HTTP_X_HUB_SIGNATURE']

  • but when in doubt as to how PHP will name a header, set up a page with <?php phpinfo(~0); 但是如果对PHP如何命名标题有疑问,请使用<?php phpinfo(~0);设置页面<?php phpinfo(~0); , and run curl with the url like curl http://ratma.net/phpinfo.php --header "X-Hub-Signature: test" -v 2>&1 | grep -i test ,并像curl http://ratma.net/phpinfo.php --header "X-Hub-Signature: test" -v 2>&1 | grep -i test一样运行curl curl http://ratma.net/phpinfo.php --header "X-Hub-Signature: test" -v 2>&1 | grep -i test curl http://ratma.net/phpinfo.php --header "X-Hub-Signature: test" -v 2>&1 | grep -i test , and you should see what the header is called. curl http://ratma.net/phpinfo.php --header "X-Hub-Signature: test" -v 2>&1 | grep -i test ,您应该看到调用标头的内容。 in this case, i got <tr><td class="e">$_SERVER['HTTP_X_HUB_SIGNATURE']</td><td class="v">test</td></tr> 在这种情况下,我得到<tr><td class="e">$_SERVER['HTTP_X_HUB_SIGNATURE']</td><td class="v">test</td></tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM