gpt4 book ai didi

java - 文件上传 + 通过 HTTP POST 参数触发 Hudson 构建

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:02:14 24 4
gpt4 key购买 nike

目前我正在寻找一种工作方法来上传文件+以下配置中的字段Hudson .当前的问题是 hudson 总是提示应该提交的表格..(请参阅本文后面的异常(exception)情况)。但是根据我阅读的文档,它应该像下面的 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>

异常(exception)是这样的:

java.lang.Error: This page expects a form submission
at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)
at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinit

最佳答案

你可能正在使用像 job/blabla/build 这样的 url 你必须尝试使用​​ job/blabla/buildWithParameters

关于java - 文件上传 + 通过 HTTP POST 参数触发 Hudson 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4398397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com