I'm writing a small Groovy script to add comment to Jira issue, but not able to break the comment into lines using new line char, in cURL it works ok.
here is a cURL code that works
curl -k -u id:pwd X POST --data {"body":"This is line1\n\nThis is line 2"} -H "Content-Type: application/json" http://examplejira.com/rest/api/2/issue/TESTKEY-1/comment
The added comment is shown correctly as
This is line 1
This is line 2
This is the Groovy codes that does not work.
HttpRequest request = new HttpPost(requestURL);
request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
request.setEntity(new StringEntity("This is line 1\n\nThisis line 2"));
HttpResponse response = client.execute(request);
System.out.println(response.getProtocolVersion());
System.out.println(response.getStatusLine().getStatusCode());
System.out.println(response.getStatusLine().getReasonPhrase());
System.out.println(response.getStatusLine().toString());
Output is
HTTP/1.1
400
HTTP/1.1 400
If I change the setEntity to
request.setEntity(new StringEntity("This is line 1 Thisis line 2"));
Then it works but without line break obviously
Anyone can help ??
p.s. also tried
request.setEntity(new StringEntity("This is line 1%0AThis is line 2"));
request.setEntity(new StringEntity("This is line 1%0A%0DThis is line 2"));
httppost request completed Ok, but %0A and %0D is output as text.
i.e. This is line 1%0A%0DThis is line 2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.