一、在请求头加上 crumb
我现在要使用 webhook 发一个 post 请求给 jenkins,结果报了 403 错误。一个可行的解决方案就是给这个请求头加上 crumb。
- 在桌面右击空白处点击
git bash , 输入以下命令获取 crumb:curl -u user:password "http://192.168.150.188:8000/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)" 上面的user:password 需要替换成你的真实账号密码,http://192.168.150.188:8000 需要替换成你自己的 ip 地址。 - 将
Jenkins-Crumb: 后面那一串符号复制下来,它就是要添加的 crumb。现在正确的命令如下:curl -H 726749d6a7473b87b93aa07dd9960b6d943ac3535e5d90a0ee49d370d2ee77fa http://192.168.150.188:8000/job/helloworld/build?token=11aa657155f7265c6b4051a18fe61d5e66 。(我原先的命令是curl http://192.168.150.188:8000/job/helloworld/build?token=11aa657155f7265c6b4051a18fe61d5e66 ,可想而知,这是错误的)。
二、取消 csrf 验证
取消 csrf 验证需要在启动参数设置,由于我的系统为 windows,所以只需要打开 jenkins 安装目录下的
这行代码的作用是关闭 csrf 验证,不关的话,gitea 的
加好参数后,在该目录命令行下输入
