模拟github服务钩子卷曲 [英] Emulate github service hooks wih curl

查看:169
本文介绍了模拟github服务钩子卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务监听github服务钩子,执行自动部署。有时我需要手动触发(没有github干预)。为此,我正在模拟github发送(post-receive-URLs)的POST请求。

I have a service listening to github service hooks, to perform automatic deployment. Sometimes I need to trigger this manually (without github intervention). For that, I am emulating the POST request that github is sending (post-receive-URLs).

我的数据( my.json )看起来像这样(github发送的有限子集 - 我不需要更多):

My data (my.json) looks like this (a limited subset of what github is sending - I do not need more):

{
  "action"      : "deploy_from_scratch_with_bundle",
  "pusher"      : { "email" : "my@email.com" },
  "ref"         : "refs/heads/master"
}

我尝试使用curl POST:

And I try to POST with curl:

curl -X POST $URL --data-urlencode "@my.json" --header "Content-Type: application/x-www-form-urlencoded"

问题是github是这样的POST:

The problem is that github is POSTing like this:

payload=%7B%22pusher%22%3A%7B%22name%22%3A%22none%22%7D%2C%22repository%22%3
A%7B%22name%22%3A%liferay-plugins%22%2C%22created_at%22%3A%222011%2F12%2F07%2011%3A52...

看到 payload = 有吗?这看起来像一个表单字段。我不知道如何结合表单字段与urlencoding。要发表表单字段,我会这样做:

See that payload= there? This looks like a form field. I do not know how to combine form fields with urlencoding. To POST form fields, I would do it like this:

curl -X POST $URL -F "payload=@my.json"

但是JSON不会被url编码。如何获得这两个?

But the JSON would not be url encoded. How to I get both?

推荐答案

curl $ URL --data-urlencode payload@my.json

这篇关于模拟github服务钩子卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆