Github支持用于通知代码更改的post-receive挂钩,在此处记录.现在,为了测试一个钩子服务器,我需要发布一些json,我想使用curl这样做.我以前做过这个,但很少,我倾向于忘记我的解决方案.
我记得,每次都很乏味.
Github人员提供此JSON文档作为将在参数上POST的数据的示例payload:
{
  "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
  "repository": {
    "url": "http://github.com/defunkt/github",
    "name": "github",
    "description": "You're lookin' at it.",
    "watchers": 5,
    "forks": 2,
    "private": 1,
    "owner": {
      "email": "chris@ozmm.org",
      "name": "defunkt"
    }
  },
  "commits": [
    {
      "id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
      "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
      "author": {
        "email": "chris@ozmm.org",
        "name": "Chris Wanstrath"
      },
      "message": "okay i give in",
      "timestamp": "2008-02-15T14:57:17-08:00",
      "added": ["filepath.rb"]
    },
    {
      "id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
      "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
      "author": {
        "email": "chris@ozmm.org",
        "name": "Chris Wanstrath"
      },
      "message": "update pricing a tad",
      "timestamp": "2008-02-15T14:36:34-08:00"
    }
  ],
  "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
  "ref": "refs/heads/master"
}
像/tmp/example.json我想的那样保存它
 $ curl -XPOST -F "payload=@/tmp/example.json" http://localhost:3000/
本来是卷曲的正确调用,但我不正确.使用我的示例项目将上述结果挂钩:
127.0.0.1 - - [17/Nov/2011 22:20:51] "POST  HTTP/1.1" 200 - 0.0295
{:filename=>"example.json", :type=>"application/octet-stream", :name=>"payload", :tempfile=>#<File:/tmp/RackMultipart20111117-11639-1ecu4i1>, :head=>"Content-Disposition: form-data; name=\"payload\"; filename=\"example.json\"\r\nContent-Type: application/octet-stream\r\n"}
鉴于该终点的行动定义:
class HomeAction < Cramp::Action
  def start
    puts params[:payload]
    render 'thanks'
    finish
  end
end
不是很期待.那么,我如何使用curl的命令行版本在参数上发布一些JSON作为数据payload呢?
| 归档时间: | 
 | 
| 查看次数: | 1532 次 | 
| 最近记录: |