我想在WWW :: Mechanize中做一個腳本,它將在Hudson中構建一份工作。腳本是這樣的:如何使用WWW :: Mechanize提交HTML中沒有的表單?
$mech->post("$hudson_url/view/All/job/$job_name/build?delay=0sec", \%job_arguments);
問題是,哈德森日誌抱怨說,它預計表單提交。以下是從哈德森日誌提取:
Caused by: java.lang.Error: This page expects a form submission
at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)
at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinitionProperty.java:116)
at hudson.model.AbstractProject.doBuild(AbstractProject.java:1531)
... 69 more
的問題是,在哈德森構建是參數化的,等等哈德森aparently生成使用JavaScript的形式。最終,哈德森將調用這個URL。我如何提出這個請求,讓哈德森認爲我正在發表一個表格?
更新:我有Chrome中顯示的請求數據。這是什麼在起作用:
Request URL:<url>/hudson/view/All/job/ReleaseThis/build?delay=0sec
Request Method:POST
Status Code:302 Moved Temporarily
Request Headers
Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:935
Content-Type:application/x-www-form-urlencoded
Cookie:screenResolution=1920x1080; JSESSIONID=B3F99F6C376318AB6331AE6F27917D52; screenResolution=1920x1080; __utmz=250097027.1291302888.1.1.utmcsr=...|utmccn=(referral)|utmcmd=referral|utmcct=/sig/Home.action; __utma=250097027.1666115034.1291302888.1291302888.1291302888.1
Host:<hudson_url>
Origin:<huson_url>
Referer:https://<hudson_url>/hudson/view/All/job/ReleaseThis/build?delay=0sec
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.84 Safari/534.13
Query String Parameters
delay:0sec
Form Data
name:URL
value:https://<url>
value:1.12-SNAPSHOT
name:RELEASE_VERSION
value:1.12-TEST16
name:UPDATE_MASTER_POM
name:PROPERTY_NAME
value:
name:DEV_VERSION
value:
name:STABLE_VERSION
value:
json:{"parameter": [{"name": "URL", "value": <url>}, {"name": "SNAPSHOT_VERSION", "value": "1.12-SNAPSHOT"}, {"name": "RELEASE_VERSION", "value": "1.12-TEST16"}, {"name": "UPDATE_MASTER_POM", "value": false}, {"name": "PROPERTY_NAME", "value": ""}, {"name": "DEV_VERSION", "value": ""}, {"name": "STABLE_VERSION", "value": ""}]}
Submit:Build
Response Headers
Connection:close
Content-Length:0
Content-Type:text/plain; charset=UTF-8
Date:Fri, 04 Feb 2011 13:33:27 GMT
Location:https://<hudson.url>/hudson/view/All/job/ReleaseThis/
Server:Apache-Coyote/1.1
Via:1.1 <hudson.url>:8890 (Apache/2.2.3)
嘗試採取交通的tcpdump的,這將然後讓您確定數據以何種格式發送。 – 2011-02-04 15:54:45