dps43378 2013-05-10 13:53 采纳率: 0%
浏览 276
已采纳

GitHub WebHook POST没有通过

I've got github webhoooks set up to send a POST to a PHP script on my server when I push to a repo. (https://help.github.com/articles/post-receive-hooks)

MY PHP script logs the connecting IP, as well as the payload received:

$date = strftime('%c');
file_put_contents('log.txt', PHP_EOL.trim($date).PHP_EOL, FILE_APPEND);
try
{
  $payload = json_decode($_REQUEST['payload']);
}
catch(Exception $e)
{
  exit(0);
}

//LOG THE POST REQUEST
file_put_contents('log.txt', print_r($payload, TRUE), FILE_APPEND);

//EXECUTE A SCRIPT WHEN THE POST REQUEST IS INITIALIZED
if ($payload->ref === 'refs/heads/master')
{
  exec('deploy.sh >> log.txt');
}

From the logs, I can see that an IP connects when I push to my repo, but no POST data is recorded. I tested with RequestBin, and confirmed that POST data present. Furthermore, if I manually put a $_GET payload variable in the URL, that is recorded (since I'm checking $_REQUEST and not just $_POST). My suspicion is that my PHP server is configured to deny POST requests from other servers. I'm using 1and1 Shared Hosting, so I don't have dedicated control, but I can SSH in, as well as configure PHP settings locally with an .ini file. Any suggestions would be greatly appreciated!

*I don't care if I do this in PHP, or some other language. If you think this might be easier using a Python or something else, that's cool too.

-Jeremy

  • 写回答

2条回答 默认 最新

  • douchun6108 2013-05-15 03:46
    关注

    Ok I figured it out by first printing the raw post data before doing the JSON decode. Turns out my PHP installation has magic quotes enabled, and automatically put escape slashes before every quote in the JSON payload. Obviously, this made the JSON invalid, and JSON_decode errored-out as a result.

    Here is the simple fix:

    $payload = json_decode(stripslashes($_REQUEST['payload']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器