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 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试