Emulate github service hooks wih curl

耗尽温柔 提交于 2019-12-06 10:26:26

问题


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 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"
}

And I try to POST with curl:

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

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...

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"

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


回答1:


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



来源:https://stackoverflow.com/questions/10119299/emulate-github-service-hooks-wih-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!