Java 文件上传+;通过HTTP POST触发Hudson构建的参数

Java 文件上传+;通过HTTP POST触发Hudson构建的参数,java,http,hudson,httpclient,hudson-api,Java,Http,Hudson,Httpclient,Hudson Api,目前,我正在寻找一个工作方法,上传一个文件+一个字段在下面的确认。当前的问题是哈德逊总是抱怨应该提交的表格(见本文后面的例外)。但是根据我读到的文档,它应该像下面的Java代码片段一样工作 HttpPost httppost = new HttpPost(triggerJobUrl); FileBody fileBody = new FileBody(releaseProperties); StringBody stringBody = new StringBody(svnURL.toStrin

目前,我正在寻找一个工作方法,上传一个文件+一个字段在下面的确认。当前的问题是哈德逊总是抱怨应该提交的表格(见本文后面的例外)。但是根据我读到的文档,它应该像下面的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依赖项如下所示:

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.0.3</version>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpcore</artifactId>
  <version>4.0.1</version>
  <type>jar</type>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpmime</artifactId>
  <version>4.0.3</version>
  <type>jar</type>
  <scope>compile</scope>

您可能正在使用类似于job/blabla/build的url。您必须尝试使用job/blabla/buildWithParameters

您好,因为imagebin链接无效,我不确定您的问题。我已经发布了一个答案,用于上传一个参数化构建的文件,curl位于。我也有同样的问题,你解决了吗?
java.lang.Error: This page expects a form submission
   at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)
   at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinit