Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting 500 error while making GET call to Jira using HttpURLConnection, works fine in postman

Abhay
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 1, 2022

Hi everyone,

I am trying to make a GET call to Jira URL in Java using HttpURLConnection - getting 500 server error

If I make same call using postman - it works.

String url = "https://jira.mydomain.com/rest/raven/2.0/api/testrun/?testExecIssueKey=T22&testIssueKey=T2;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
String basicAuth = "Basic :" + new String(Base64.getEncoder().encode(credentials.getBytes()));

con.setRequestProperty ("Authorization", basicAuth);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println(responseCode);

Can someone please help and see whats going wrong? 

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová
Community Champion
July 3, 2022

Hi @abhay99 ,

welcome to the Atlassian community!

What seems suspicious in your code to me:

1)

String url = "https://jira.mydomain.com/rest/raven/2.0/api/testrun/?testExecIssueKey=T22&testIssueKey=T2;

Possible missing double-quote in the end of the line?

String url = "https://jira.mydomain.com/rest/raven/2.0/api/testrun/?testExecIssueKey=T22&testIssueKey=T2";

 2)

String basicAuth = "Basic :" + new String(Base64.getEncoder().encode(credentials.getBytes()));

There should't be : after word Basic

String basicAuth = "Basic " + new String(Base64.getEncoder().encode(credentials.getBytes()));
Abhay
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 4, 2022

Thanks for your response. 1st pointer was a typo and 2nd pointer did the trick, it works now. Very weird that for this reason I was getting 500 error, should have got 401 instead. Anyway, it works now. Thanks.

Like Hana Kučerová likes this

Suggest an answer

Log in or Sign up to answer