我成功地使用了这个:
curl -X POST -H "Content-Type:application/xml" -d "<project><builders/><publishers/><buildWrappers/></project>" "http://USER:PASSWORD@JENKINS_HOST/createItem?name=NEW_JOB_NAME"
我将它转换为这个python代码:
url = "http://USER:PASS@HOST/createItem"
payload = { 'name' : 'NEW_JOB_NAME' }
headers = {"Content-Type:application/xml"}
r = requests.post(url, data=payload, headers=headers)
我应该把"<project><builders/><publishers/><buildWrappers/></project>"
部分放在哪里?
答案 0 :(得分:1)
您需要将GET参数与URI的其余部分放在一起,而不是尝试将GET参数拆分为有效负载。有效负载应该包含POST数据(&#34;主体&#34; HTTP请求,var app = require('express'),
url = require('url),
b= require('B')(app, url),
c= require('C')(app, url);
参数到cURL)。
我还将身份验证提取到请求&#39;首选语法。
-d
要确认结果,您可以添加以下行:
url = 'http://HOST/createItem?name=NEW_JOB_NAME'
auth = ('USER', 'PASS')
payload = '<project><builders/><publishers/><buildWrappers/></project>'
headers = {"Content-Type": "application/xml"}
r = requests.post(url, data=payload, auth=auth, headers=headers)