Community Announcements have moved! To stay up to date, please join the new Community Announcements group today. Learn more
×Hi All,
Iam working in a client project,there jira is hosted in aws .iam trying to add attachments to issue via rest api, it is working fine in postman and i used the same code in other cloud instances there also working fine,but in the client hosted instance it is not working giving 400 error ,other apis working fine.please find my below code .Please provide the solution for this.
final String username = "****";
final String password = "****";
final String proxyUrl = "****";
final int port = 8080;CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(proxyUrl, port),
new UsernamePasswordCredentials(username, password)
);HttpHost myProxy = new HttpHost(proxyUrl, port);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();clientBuilder.setProxy(myProxy).setDefaultCredentialsProvider(credsProvider).disableCookieManagement();
HttpClient httpClient = clientBuilder.build();
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(factory);
//Headers
HttpHeaders headers = new HttpHeaders();
String auth = "****" + ":" + "****";
String basicAuth = "Basic " + new String(new sun.misc.BASE64Encoder().encode(auth.getBytes()));
headers.set("Authorization", basicAuth);
headers.set("X-Atlassian-Token", "no-check");
//map
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
FileSystemResource value = new FileSystemResource(new File("D://test.txt"));
map.add("file", value);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
ResponseEntity<String> d = restTemplate.exchange("https://*******/rest/api/2/issue/***-1/attachments", HttpMethod.POST, requestEntity, String.class);