Я пытаюсь выполнить метод Post для создания контента, используя String как Json Obje c, но получаю 400. Согласно Google, 400 используется, когда у вас есть синтаксическая ошибка.
Вот метод, который я использовал для работы на другом сервере, единственное, что я изменил, - это объект json
Может ли кто-нибудь помочь?
public int createJiraEmployee(Employee employee)throws ClientProtocolException, IOException, Exception {
//prepare request
CloseableHttpClient client = HttpClients.createDefault();
String json = "{\"fields\":{\"project\":{\"key\":\"CHECK\"}"
+ ",\"issuetype\":{\"name\":\"New Joiner Checklist\"},"
+ "\"summary\":\"Checklist New Joiner Checklist\""
+ ",\"description\":\"Please do all tasks related to HR Checklist\","
+ "\"customfield_12721\":\"FirstnameTest\","
+ "\"customfield_12722\":\"lastnametest\","
+ "\"customfield_12723\":{\"value\":\"Employee\"},"
+ "\"customfield_12732\":\"PRESALES CONSULTANT\","
+ "\"customfield_12725\":\"1003148\","
+ "\"customfield_12726\":{\"value\":\"Company Test\"},"
+ "\"customfield_12685\":{\"value\":\"BUtest\"},"
+ "\"customfield_12673\":{\"value\":\"Department test\"},"
+ "\"customfield_12727\":{\"value\":\"IT\"},"
+ "\"customfield_12667\":{\"name\":\"managerTest\"},"
+ "\"customfield_12708\":\"2020-04-08\","
+ "\"customfield_14000\":\"France\","
+ "\"customfield_14001\":\"Teamtest\","
+ "\"customfield_14002\":\"Team2test\"}}";
SimpleDateFormat formatter= new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss z");
try {
json = URLEncoder.encode(json, StandardCharsets.UTF_8.toString());
//ATTENTION ERREUR EXPRES
urlCreateEmployee += json ;
HttpPost httpPost = new HttpPost(urlCreateEmployee);
// String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
String encodedAuth = Base64.getEncoder().encodeToString(("username:password").getBytes());
authHeaderValue = "Basic " + encodedAuth;
httpPost.setHeader("Authorization", authHeaderValue);
//call WS
CloseableHttpResponse response = client.execute(httpPost);
//Get response
// String res = EntityUtils.toString(response.getEntity());
int res = response.getStatusLine().getStatusCode();