java构造post参数_java – 通过HTTP POST文件上传参数来触发Hudson构建

目前我正在寻找一种工作方法,在

Hudson的以下配置中上传文件一个字段.目前的问题是Hudson总是抱怨应该提交的表格..(参见本文稍后的例外).但根据我阅读的文档,它应该像下面的Java代码片段一样工作…

HttpPost httppost = new HttpPost(triggerJobUrl);

FileBody fileBody = new FileBody(releaseProperties);

StringBody stringBody = new StringBody(svnURL.toString());

MultipartEntity mentity = new MultipartEntity();

mentity.addPart("trunk/release.properties", fileBody);

mentity.addPart("SVNURL", stringBody);

httppost.setEntity(mentity);

HttpResponse response = null;

try {

response = httpClient.execute(httppost);

} catch (ClientProtocolException e) {

throw new HudsonException("http protocol error.", e);

} catch (IOException e) {

throw new HudsonException("connection aborted.", e);

}

if (response.getStatusLine().getStatusCode() != 200) {

throw new HudsonException("Unexpected status code received " + response.getStatusLine().getStatusCode());

}

HttpEntity resEntity = response.getEntity();

if (resEntity != null) {

try {

resEntity.consumeContent();

} catch (IOException e) {

throw new HudsonException(

"if an I/O error occurs. This indicates that connection keep-alive is not possible.", e);

}

}

我目前的Maven依赖关系如下:

org.apache.httpcomponents

httpclient

4.0.3

org.apache.httpcomponents

httpcore

4.0.1

jar

compile

org.apache.httpcomponents

httpmime

4.0.3

jar

compile

例外是这样的:

java.lang.Error: This page expects a form submission

at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)

at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值