【发布时间】:2019-01-12 05:31:26
【问题描述】:
下面的代码可以很好地在 JIRA 中附加文件,这里只有一个问题 我不能使用 MultipartEntityBuilder 因为它需要在 pom 中添加新的依赖项,这是不允许的,有人可以建议我可以在那里使用哪个基本 API 吗?在此先感谢
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost("https://xxxx.zzzz.net/rest/api/2/issue/" + issueID +"/attachments");
postRequest.setHeader("Authorization", "Basic <AUTHSTRING>");
postRequest.setHeader("X-Atlassian-Token", "nocheck");
File file = new File("C:\\Users\\MKumar\\Desktop\\Oauth_JIRA.rtf");
URL url = new URL("C:\\Users\\MKumar\\Desktop\\Oauth_JIRA.rtf");
MultipartEntityBuilder builder = MultipartBodyBuilder.create();
// This attaches the file to the POST:
builder.addBinaryBody(
"file",
new FileInputStream(file),
ContentType.MULTIPART_FORM_DATA,
file.getName()
);
HttpEntity multipart = builder.build();
postRequest.setEntity(multipart);
HttpResponse response = httpClient.execute(postRequest);
【问题讨论】:
-
注意(!):在以
postRequest.setHeader("Authorization"开头的行中,您有一个看起来像真实用户名+密码的授权字符串。它只是 base64 编码的。那不应该公开发布。我已经对其进行了编辑,但是您可能应该删除此问题以将其从公共历史记录中删除,然后在没有敏感信息的情况下重新发布。您可能还想更改您的 Atlassian 登录信息,因为它可能已经被爬虫存档在其他地方。